diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 5c4079d96..03a29bb14 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1106,9 +1106,9 @@ void StoreMove(AxisDirection moveDir) static AxisDirectionRepeater repeater; moveDir = repeater.Get(moveDir); if (moveDir.y == AxisDirectionY_UP) - STextUp(); + StoreUp(); else if (moveDir.y == AxisDirectionY_DOWN) - STextDown(); + StoreDown(); } using HandleLeftStickOrDPadFn = void (*)(devilution::AxisDirection); diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 715e95ac0..c4582b989 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -928,7 +928,7 @@ bool PressEscKey() } if (stextflag != STORE_NONE) { - STextESC(); + StoreESC(); rv = true; } @@ -1011,7 +1011,7 @@ static void PressKey(int vkey) if (GetAsyncKeyState(DVL_VK_MENU)) { dx_reinit(); } else if (stextflag != STORE_NONE) { - STextEnter(); + StoreEnter(); } else if (questlog) { QuestlogEnter(); } else { @@ -1019,7 +1019,7 @@ static void PressKey(int vkey) } } else if (vkey == DVL_VK_UP) { if (stextflag != STORE_NONE) { - STextUp(); + StoreUp(); } else if (questlog) { QuestlogUp(); } else if (helpflag) { @@ -1029,7 +1029,7 @@ static void PressKey(int vkey) } } else if (vkey == DVL_VK_DOWN) { if (stextflag != STORE_NONE) { - STextDown(); + StoreDown(); } else if (questlog) { QuestlogDown(); } else if (helpflag) { @@ -1039,11 +1039,11 @@ static void PressKey(int vkey) } } else if (vkey == DVL_VK_PRIOR) { if (stextflag != STORE_NONE) { - STextPrior(); + StorePrior(); } } else if (vkey == DVL_VK_NEXT) { if (stextflag != STORE_NONE) { - STextNext(); + StoreNext(); } } else if (vkey == DVL_VK_LEFT) { if (AutomapActive && !talkflag) { diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 6332c36b6..7ac8fbd9a 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -2288,7 +2288,7 @@ void drlg_l1_set_corner_room(int rx1, int ry1) } } -static void DrlgL5Ftvr(int i, int j, int x, int y, int d) +static void DrlgL5FTransparencyValueR(int i, int j, int x, int y, int d) { if (dTransVal[x][y] != 0 || dungeon[i][j] != 13) { if (d == 1) { @@ -2322,14 +2322,14 @@ static void DrlgL5Ftvr(int i, int j, int x, int y, int d) dTransVal[x + 1][y] = TransVal; dTransVal[x][y + 1] = TransVal; dTransVal[x + 1][y + 1] = TransVal; - DrlgL5Ftvr(i + 1, j, x + 2, y, 1); - DrlgL5Ftvr(i - 1, j, x - 2, y, 2); - DrlgL5Ftvr(i, j + 1, x, y + 2, 3); - DrlgL5Ftvr(i, j - 1, x, y - 2, 4); - DrlgL5Ftvr(i - 1, j - 1, x - 2, y - 2, 5); - DrlgL5Ftvr(i + 1, j - 1, x + 2, y - 2, 6); - DrlgL5Ftvr(i - 1, j + 1, x - 2, y + 2, 7); - DrlgL5Ftvr(i + 1, j + 1, x + 2, y + 2, 8); + DrlgL5FTransparencyValueR(i + 1, j, x + 2, y, 1); + DrlgL5FTransparencyValueR(i - 1, j, x - 2, y, 2); + DrlgL5FTransparencyValueR(i, j + 1, x, y + 2, 3); + DrlgL5FTransparencyValueR(i, j - 1, x, y - 2, 4); + DrlgL5FTransparencyValueR(i - 1, j - 1, x - 2, y - 2, 5); + DrlgL5FTransparencyValueR(i + 1, j - 1, x + 2, y - 2, 6); + DrlgL5FTransparencyValueR(i - 1, j + 1, x - 2, y + 2, 7); + DrlgL5FTransparencyValueR(i + 1, j + 1, x + 2, y + 2, 8); } static void DrlgL5FloodTVal() @@ -2341,7 +2341,7 @@ static void DrlgL5FloodTVal() for (int i = 0; i < DMAXX; i++) { if (dungeon[i][j] == 13 && dTransVal[xx][yy] == 0) { - DrlgL5Ftvr(i, j, xx, yy, 0); + DrlgL5FTransparencyValueR(i, j, xx, yy, 0); TransVal++; } xx += 2; diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index 7ad0f668a..7724d4c42 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1612,7 +1612,7 @@ int Patterns[100][10] = { } // namespace -static bool DRLG_L2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) { int sw = miniset[0]; int sh = miniset[1]; @@ -1697,7 +1697,7 @@ static bool DRLG_L2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, return true; } -static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper) +static void DrlgL2PlaceRndSet(const BYTE *miniset, int rndper) { int sw = miniset[0]; int sh = miniset[1]; @@ -1745,7 +1745,7 @@ static void DRLG_L2PlaceRndSet(const BYTE *miniset, int rndper) } } -static void DRLG_L2Subs() +static void DrlgL2Subs() { for (int y = 0; y < DMAXY; y++) { for (int x = 0; x < DMAXX; x++) { @@ -1781,7 +1781,7 @@ static void DRLG_L2Subs() } } -static void DRLG_L2Shadows() +static void DrlgL2Shadows() { int8_t sd[2][2]; @@ -1825,7 +1825,7 @@ void InitDungeon() } } -static void DRLG_LoadL2SP() +static void DrlgLoadL2SetPiece() { setloadflag = false; @@ -1843,12 +1843,12 @@ static void DRLG_LoadL2SP() } } -static void DRLG_FreeL2SP() +static void DrlgFreeL2SetPiece() { pSetPiece = nullptr; } -static void DRLG_L2SetRoom(int rx1, int ry1) +static void DrlgL2SetRoom(int rx1, int ry1) { int width = SDL_SwapLE16(pSetPiece[0]); int height = SDL_SwapLE16(pSetPiece[1]); @@ -2323,7 +2323,7 @@ static void L2TileFix() } } -static bool DL2_Cont(bool x1f, bool y1f, bool x2f, bool y2f) +static bool DL2Cont(bool x1f, bool y1f, bool x2f, bool y2f) { if (x1f && x2f && y1f && y2f) { return false; @@ -2338,7 +2338,7 @@ static bool DL2_Cont(bool x1f, bool y1f, bool x2f, bool y2f) return false; } -static int DL2_NumNoChar() +static int DL2NumNoChar() { int t = 0; for (int jj = 0; jj < DMAXY; jj++) { @@ -2352,7 +2352,7 @@ static int DL2_NumNoChar() return t; } -static void DL2_DrawRoom(int x1, int y1, int x2, int y2) +static void DL2DrawRoom(int x1, int y1, int x2, int y2) { for (int jj = y1; jj <= y2; jj++) { for (int ii = x1; ii <= x2; ii++) { @@ -2369,7 +2369,7 @@ static void DL2_DrawRoom(int x1, int y1, int x2, int y2) } } -static void DL2_KnockWalls(int x1, int y1, int x2, int y2) +static void DL2KnockWalls(int x1, int y1, int x2, int y2) { for (int ii = x1 + 1; ii < x2; ii++) { if (predungeon[ii][y1 - 1] == 46 && predungeon[ii][y1 + 1] == 46) { @@ -2401,10 +2401,10 @@ static void DL2_KnockWalls(int x1, int y1, int x2, int y2) } } -static bool DL2_FillVoids() +static bool DL2FillVoids() { int to = 0; - while (DL2_NumNoChar() > 700 && to < 100) { + while (DL2NumNoChar() > 700 && to < 100) { int xx = GenerateRnd(38) + 1; int yy = GenerateRnd(38) + 1; if (predungeon[xx][yy] != 35) { @@ -2451,7 +2451,7 @@ static bool DL2_FillVoids() xf2 = true; } } - if (DL2_Cont(xf1, yf1, xf2, yf2)) { + if (DL2Cont(xf1, yf1, xf2, yf2)) { int x1 = xx; if (xf1) { x1--; @@ -2514,8 +2514,8 @@ static bool DL2_FillVoids() } x2 -= 2; if (x2 - x1 > 5) { - DL2_DrawRoom(x1, y1, x2, y2); - DL2_KnockWalls(x1, y1, x2, y2); + DL2DrawRoom(x1, y1, x2, y2); + DL2KnockWalls(x1, y1, x2, y2); } } } else if (!xf2) { @@ -2564,8 +2564,8 @@ static bool DL2_FillVoids() } x1 += 2; if (x2 - x1 > 5) { - DL2_DrawRoom(x1, y1, x2, y2); - DL2_KnockWalls(x1, y1, x2, y2); + DL2DrawRoom(x1, y1, x2, y2); + DL2KnockWalls(x1, y1, x2, y2); } } } else if (!yf1) { @@ -2614,8 +2614,8 @@ static bool DL2_FillVoids() } y2 -= 2; if (y2 - y1 > 5) { - DL2_DrawRoom(x1, y1, x2, y2); - DL2_KnockWalls(x1, y1, x2, y2); + DL2DrawRoom(x1, y1, x2, y2); + DL2KnockWalls(x1, y1, x2, y2); } } } else if (!yf2) { @@ -2664,8 +2664,8 @@ static bool DL2_FillVoids() } y1 += 2; if (y2 - y1 > 5) { - DL2_DrawRoom(x1, y1, x2, y2); - DL2_KnockWalls(x1, y1, x2, y2); + DL2DrawRoom(x1, y1, x2, y2); + DL2KnockWalls(x1, y1, x2, y2); } } } @@ -2673,7 +2673,7 @@ static bool DL2_FillVoids() to++; } - return DL2_NumNoChar() <= 700; + return DL2NumNoChar() <= 700; } static bool CreateDungeon() @@ -2739,7 +2739,7 @@ static bool CreateDungeon() } } - if (!DL2_FillVoids()) { + if (!DL2FillVoids()) { return false; } @@ -2752,12 +2752,12 @@ static bool CreateDungeon() return true; } -static void DRLG_L2Pass3() +static void DrlgL2Pass3() { DRLG_LPass3(12 - 1); } -static void DRLG_L2FTVR(int i, int j, int x, int y, int d) +static void DrlgL2FTransparencyValueR(int i, int j, int x, int y, int d) { if (dTransVal[x][y] != 0 || dungeon[i][j] != 3) { if (d == 1) { @@ -2793,25 +2793,25 @@ static void DRLG_L2FTVR(int i, int j, int x, int y, int d) dTransVal[x + 1][y] = TransVal; dTransVal[x][y + 1] = TransVal; dTransVal[x + 1][y + 1] = TransVal; - DRLG_L2FTVR(i + 1, j, x + 2, y, 1); - DRLG_L2FTVR(i - 1, j, x - 2, y, 2); - DRLG_L2FTVR(i, j + 1, x, y + 2, 3); - DRLG_L2FTVR(i, j - 1, x, y - 2, 4); - DRLG_L2FTVR(i - 1, j - 1, x - 2, y - 2, 5); - DRLG_L2FTVR(i + 1, j - 1, x + 2, y - 2, 6); - DRLG_L2FTVR(i - 1, j + 1, x - 2, y + 2, 7); - DRLG_L2FTVR(i + 1, j + 1, x + 2, y + 2, 8); + DrlgL2FTransparencyValueR(i + 1, j, x + 2, y, 1); + DrlgL2FTransparencyValueR(i - 1, j, x - 2, y, 2); + DrlgL2FTransparencyValueR(i, j + 1, x, y + 2, 3); + DrlgL2FTransparencyValueR(i, j - 1, x, y - 2, 4); + DrlgL2FTransparencyValueR(i - 1, j - 1, x - 2, y - 2, 5); + DrlgL2FTransparencyValueR(i + 1, j - 1, x + 2, y - 2, 6); + DrlgL2FTransparencyValueR(i - 1, j + 1, x - 2, y + 2, 7); + DrlgL2FTransparencyValueR(i + 1, j + 1, x + 2, y + 2, 8); } } -static void DRLG_L2FloodTVal() +static void DrlgL2FloodTVal() { int yy = 16; for (int j = 0; j < DMAXY; j++) { int xx = 16; for (int i = 0; i < DMAXX; i++) { if (dungeon[i][j] == 3 && dTransVal[xx][yy] == 0) { - DRLG_L2FTVR(i, j, xx, yy, 0); + DrlgL2FTransparencyValueR(i, j, xx, yy, 0); TransVal++; } xx += 2; @@ -2820,7 +2820,7 @@ static void DRLG_L2FloodTVal() } } -static void DRLG_L2TransFix() +static void DrlgL2TransFix() { int yy = 16; for (int j = 0; j < DMAXY; j++) { @@ -2957,7 +2957,7 @@ void L2DoorFix() } } -static void DRLG_L2(lvl_entry entry) +static void DrlgL2(lvl_entry entry) { bool doneflag = false; while (!doneflag) { @@ -2969,34 +2969,34 @@ static void DRLG_L2(lvl_entry entry) } L2TileFix(); if (setloadflag) { - DRLG_L2SetRoom(nSx1, nSy1); + DrlgL2SetRoom(nSx1, nSy1); } - DRLG_L2FloodTVal(); - DRLG_L2TransFix(); + DrlgL2FloodTVal(); + DrlgL2TransFix(); if (entry == ENTRY_MAIN) { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true, 0); if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); } } ViewY -= 2; } else if (entry == ENTRY_PREV) { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true, 1); if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); } } ViewX--; } else { - doneflag = DRLG_L2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag) { - doneflag = DRLG_L2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); if (doneflag && currlevel == 5) { - doneflag = DRLG_L2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true, 6); } } ViewY -= 2; @@ -3008,116 +3008,116 @@ static void DRLG_L2(lvl_entry entry) L2DirtFix(); DRLG_PlaceThemeRooms(6, 10, 3, 0, false); - DRLG_L2PlaceRndSet(CTRDOOR1, 100); - DRLG_L2PlaceRndSet(CTRDOOR2, 100); - DRLG_L2PlaceRndSet(CTRDOOR3, 100); - DRLG_L2PlaceRndSet(CTRDOOR4, 100); - DRLG_L2PlaceRndSet(CTRDOOR5, 100); - DRLG_L2PlaceRndSet(CTRDOOR6, 100); - DRLG_L2PlaceRndSet(CTRDOOR7, 100); - DRLG_L2PlaceRndSet(CTRDOOR8, 100); - DRLG_L2PlaceRndSet(VARCH33, 100); - DRLG_L2PlaceRndSet(VARCH34, 100); - DRLG_L2PlaceRndSet(VARCH35, 100); - DRLG_L2PlaceRndSet(VARCH36, 100); - DRLG_L2PlaceRndSet(VARCH37, 100); - DRLG_L2PlaceRndSet(VARCH38, 100); - DRLG_L2PlaceRndSet(VARCH39, 100); - DRLG_L2PlaceRndSet(VARCH40, 100); - DRLG_L2PlaceRndSet(VARCH1, 100); - DRLG_L2PlaceRndSet(VARCH2, 100); - DRLG_L2PlaceRndSet(VARCH3, 100); - DRLG_L2PlaceRndSet(VARCH4, 100); - DRLG_L2PlaceRndSet(VARCH5, 100); - DRLG_L2PlaceRndSet(VARCH6, 100); - DRLG_L2PlaceRndSet(VARCH7, 100); - DRLG_L2PlaceRndSet(VARCH8, 100); - DRLG_L2PlaceRndSet(VARCH9, 100); - DRLG_L2PlaceRndSet(VARCH10, 100); - DRLG_L2PlaceRndSet(VARCH11, 100); - DRLG_L2PlaceRndSet(VARCH12, 100); - DRLG_L2PlaceRndSet(VARCH13, 100); - DRLG_L2PlaceRndSet(VARCH14, 100); - DRLG_L2PlaceRndSet(VARCH15, 100); - DRLG_L2PlaceRndSet(VARCH16, 100); - DRLG_L2PlaceRndSet(VARCH17, 100); - DRLG_L2PlaceRndSet(VARCH18, 100); - DRLG_L2PlaceRndSet(VARCH19, 100); - DRLG_L2PlaceRndSet(VARCH20, 100); - DRLG_L2PlaceRndSet(VARCH21, 100); - DRLG_L2PlaceRndSet(VARCH22, 100); - DRLG_L2PlaceRndSet(VARCH23, 100); - DRLG_L2PlaceRndSet(VARCH24, 100); - DRLG_L2PlaceRndSet(VARCH25, 100); - DRLG_L2PlaceRndSet(VARCH26, 100); - DRLG_L2PlaceRndSet(VARCH27, 100); - DRLG_L2PlaceRndSet(VARCH28, 100); - DRLG_L2PlaceRndSet(VARCH29, 100); - DRLG_L2PlaceRndSet(VARCH30, 100); - DRLG_L2PlaceRndSet(VARCH31, 100); - DRLG_L2PlaceRndSet(VARCH32, 100); - DRLG_L2PlaceRndSet(HARCH1, 100); - DRLG_L2PlaceRndSet(HARCH2, 100); - DRLG_L2PlaceRndSet(HARCH3, 100); - DRLG_L2PlaceRndSet(HARCH4, 100); - DRLG_L2PlaceRndSet(HARCH5, 100); - DRLG_L2PlaceRndSet(HARCH6, 100); - DRLG_L2PlaceRndSet(HARCH7, 100); - DRLG_L2PlaceRndSet(HARCH8, 100); - DRLG_L2PlaceRndSet(HARCH9, 100); - DRLG_L2PlaceRndSet(HARCH10, 100); - DRLG_L2PlaceRndSet(HARCH11, 100); - DRLG_L2PlaceRndSet(HARCH12, 100); - DRLG_L2PlaceRndSet(HARCH13, 100); - DRLG_L2PlaceRndSet(HARCH14, 100); - DRLG_L2PlaceRndSet(HARCH15, 100); - DRLG_L2PlaceRndSet(HARCH16, 100); - DRLG_L2PlaceRndSet(HARCH17, 100); - DRLG_L2PlaceRndSet(HARCH18, 100); - DRLG_L2PlaceRndSet(HARCH19, 100); - DRLG_L2PlaceRndSet(HARCH20, 100); - DRLG_L2PlaceRndSet(HARCH21, 100); - DRLG_L2PlaceRndSet(HARCH22, 100); - DRLG_L2PlaceRndSet(HARCH23, 100); - DRLG_L2PlaceRndSet(HARCH24, 100); - DRLG_L2PlaceRndSet(HARCH25, 100); - DRLG_L2PlaceRndSet(HARCH26, 100); - DRLG_L2PlaceRndSet(HARCH27, 100); - DRLG_L2PlaceRndSet(HARCH28, 100); - DRLG_L2PlaceRndSet(HARCH29, 100); - DRLG_L2PlaceRndSet(HARCH30, 100); - DRLG_L2PlaceRndSet(HARCH31, 100); - DRLG_L2PlaceRndSet(HARCH32, 100); - DRLG_L2PlaceRndSet(HARCH33, 100); - DRLG_L2PlaceRndSet(HARCH34, 100); - DRLG_L2PlaceRndSet(HARCH35, 100); - DRLG_L2PlaceRndSet(HARCH36, 100); - DRLG_L2PlaceRndSet(HARCH37, 100); - DRLG_L2PlaceRndSet(HARCH38, 100); - DRLG_L2PlaceRndSet(HARCH39, 100); - DRLG_L2PlaceRndSet(HARCH40, 100); - DRLG_L2PlaceRndSet(CRUSHCOL, 99); - DRLG_L2PlaceRndSet(RUINS1, 10); - DRLG_L2PlaceRndSet(RUINS2, 10); - DRLG_L2PlaceRndSet(RUINS3, 10); - DRLG_L2PlaceRndSet(RUINS4, 10); - DRLG_L2PlaceRndSet(RUINS5, 10); - DRLG_L2PlaceRndSet(RUINS6, 10); - DRLG_L2PlaceRndSet(RUINS7, 50); - DRLG_L2PlaceRndSet(PANCREAS1, 1); - DRLG_L2PlaceRndSet(PANCREAS2, 1); - DRLG_L2PlaceRndSet(BIG1, 3); - DRLG_L2PlaceRndSet(BIG2, 3); - DRLG_L2PlaceRndSet(BIG3, 3); - DRLG_L2PlaceRndSet(BIG4, 3); - DRLG_L2PlaceRndSet(BIG5, 3); - DRLG_L2PlaceRndSet(BIG6, 20); - DRLG_L2PlaceRndSet(BIG7, 20); - DRLG_L2PlaceRndSet(BIG8, 3); - DRLG_L2PlaceRndSet(BIG9, 20); - DRLG_L2PlaceRndSet(BIG10, 20); - DRLG_L2Subs(); - DRLG_L2Shadows(); + DrlgL2PlaceRndSet(CTRDOOR1, 100); + DrlgL2PlaceRndSet(CTRDOOR2, 100); + DrlgL2PlaceRndSet(CTRDOOR3, 100); + DrlgL2PlaceRndSet(CTRDOOR4, 100); + DrlgL2PlaceRndSet(CTRDOOR5, 100); + DrlgL2PlaceRndSet(CTRDOOR6, 100); + DrlgL2PlaceRndSet(CTRDOOR7, 100); + DrlgL2PlaceRndSet(CTRDOOR8, 100); + DrlgL2PlaceRndSet(VARCH33, 100); + DrlgL2PlaceRndSet(VARCH34, 100); + DrlgL2PlaceRndSet(VARCH35, 100); + DrlgL2PlaceRndSet(VARCH36, 100); + DrlgL2PlaceRndSet(VARCH37, 100); + DrlgL2PlaceRndSet(VARCH38, 100); + DrlgL2PlaceRndSet(VARCH39, 100); + DrlgL2PlaceRndSet(VARCH40, 100); + DrlgL2PlaceRndSet(VARCH1, 100); + DrlgL2PlaceRndSet(VARCH2, 100); + DrlgL2PlaceRndSet(VARCH3, 100); + DrlgL2PlaceRndSet(VARCH4, 100); + DrlgL2PlaceRndSet(VARCH5, 100); + DrlgL2PlaceRndSet(VARCH6, 100); + DrlgL2PlaceRndSet(VARCH7, 100); + DrlgL2PlaceRndSet(VARCH8, 100); + DrlgL2PlaceRndSet(VARCH9, 100); + DrlgL2PlaceRndSet(VARCH10, 100); + DrlgL2PlaceRndSet(VARCH11, 100); + DrlgL2PlaceRndSet(VARCH12, 100); + DrlgL2PlaceRndSet(VARCH13, 100); + DrlgL2PlaceRndSet(VARCH14, 100); + DrlgL2PlaceRndSet(VARCH15, 100); + DrlgL2PlaceRndSet(VARCH16, 100); + DrlgL2PlaceRndSet(VARCH17, 100); + DrlgL2PlaceRndSet(VARCH18, 100); + DrlgL2PlaceRndSet(VARCH19, 100); + DrlgL2PlaceRndSet(VARCH20, 100); + DrlgL2PlaceRndSet(VARCH21, 100); + DrlgL2PlaceRndSet(VARCH22, 100); + DrlgL2PlaceRndSet(VARCH23, 100); + DrlgL2PlaceRndSet(VARCH24, 100); + DrlgL2PlaceRndSet(VARCH25, 100); + DrlgL2PlaceRndSet(VARCH26, 100); + DrlgL2PlaceRndSet(VARCH27, 100); + DrlgL2PlaceRndSet(VARCH28, 100); + DrlgL2PlaceRndSet(VARCH29, 100); + DrlgL2PlaceRndSet(VARCH30, 100); + DrlgL2PlaceRndSet(VARCH31, 100); + DrlgL2PlaceRndSet(VARCH32, 100); + DrlgL2PlaceRndSet(HARCH1, 100); + DrlgL2PlaceRndSet(HARCH2, 100); + DrlgL2PlaceRndSet(HARCH3, 100); + DrlgL2PlaceRndSet(HARCH4, 100); + DrlgL2PlaceRndSet(HARCH5, 100); + DrlgL2PlaceRndSet(HARCH6, 100); + DrlgL2PlaceRndSet(HARCH7, 100); + DrlgL2PlaceRndSet(HARCH8, 100); + DrlgL2PlaceRndSet(HARCH9, 100); + DrlgL2PlaceRndSet(HARCH10, 100); + DrlgL2PlaceRndSet(HARCH11, 100); + DrlgL2PlaceRndSet(HARCH12, 100); + DrlgL2PlaceRndSet(HARCH13, 100); + DrlgL2PlaceRndSet(HARCH14, 100); + DrlgL2PlaceRndSet(HARCH15, 100); + DrlgL2PlaceRndSet(HARCH16, 100); + DrlgL2PlaceRndSet(HARCH17, 100); + DrlgL2PlaceRndSet(HARCH18, 100); + DrlgL2PlaceRndSet(HARCH19, 100); + DrlgL2PlaceRndSet(HARCH20, 100); + DrlgL2PlaceRndSet(HARCH21, 100); + DrlgL2PlaceRndSet(HARCH22, 100); + DrlgL2PlaceRndSet(HARCH23, 100); + DrlgL2PlaceRndSet(HARCH24, 100); + DrlgL2PlaceRndSet(HARCH25, 100); + DrlgL2PlaceRndSet(HARCH26, 100); + DrlgL2PlaceRndSet(HARCH27, 100); + DrlgL2PlaceRndSet(HARCH28, 100); + DrlgL2PlaceRndSet(HARCH29, 100); + DrlgL2PlaceRndSet(HARCH30, 100); + DrlgL2PlaceRndSet(HARCH31, 100); + DrlgL2PlaceRndSet(HARCH32, 100); + DrlgL2PlaceRndSet(HARCH33, 100); + DrlgL2PlaceRndSet(HARCH34, 100); + DrlgL2PlaceRndSet(HARCH35, 100); + DrlgL2PlaceRndSet(HARCH36, 100); + DrlgL2PlaceRndSet(HARCH37, 100); + DrlgL2PlaceRndSet(HARCH38, 100); + DrlgL2PlaceRndSet(HARCH39, 100); + DrlgL2PlaceRndSet(HARCH40, 100); + DrlgL2PlaceRndSet(CRUSHCOL, 99); + DrlgL2PlaceRndSet(RUINS1, 10); + DrlgL2PlaceRndSet(RUINS2, 10); + DrlgL2PlaceRndSet(RUINS3, 10); + DrlgL2PlaceRndSet(RUINS4, 10); + DrlgL2PlaceRndSet(RUINS5, 10); + DrlgL2PlaceRndSet(RUINS6, 10); + DrlgL2PlaceRndSet(RUINS7, 50); + DrlgL2PlaceRndSet(PANCREAS1, 1); + DrlgL2PlaceRndSet(PANCREAS2, 1); + DrlgL2PlaceRndSet(BIG1, 3); + DrlgL2PlaceRndSet(BIG2, 3); + DrlgL2PlaceRndSet(BIG3, 3); + DrlgL2PlaceRndSet(BIG4, 3); + DrlgL2PlaceRndSet(BIG5, 3); + DrlgL2PlaceRndSet(BIG6, 20); + DrlgL2PlaceRndSet(BIG7, 20); + DrlgL2PlaceRndSet(BIG8, 3); + DrlgL2PlaceRndSet(BIG9, 20); + DrlgL2PlaceRndSet(BIG10, 20); + DrlgL2Subs(); + DrlgL2Shadows(); for (int j = 0; j < DMAXY; j++) { for (int i = 0; i < DMAXX; i++) { @@ -3129,7 +3129,7 @@ static void DRLG_L2(lvl_entry entry) DRLG_CheckQuests(nSx1, nSy1); } -static void DRLG_InitL2Vals() +static void DrlgInitL2Vals() { int pc; @@ -3209,7 +3209,7 @@ void LoadL2Dungeon(const char *path, int vx, int vy) LoadL2DungeonData(dunData.get()); - DRLG_L2Pass3(); + DrlgL2Pass3(); DRLG_Init_Globals(); for (int j = 0; j < MAXDUNY; j++) { @@ -3296,11 +3296,11 @@ void CreateL2Dungeon(uint32_t rseed, lvl_entry entry) DRLG_InitTrans(); DRLG_InitSetPC(); - DRLG_LoadL2SP(); - DRLG_L2(entry); - DRLG_L2Pass3(); - DRLG_FreeL2SP(); - DRLG_InitL2Vals(); + DrlgLoadL2SetPiece(); + DrlgL2(entry); + DrlgL2Pass3(); + DrlgFreeL2SetPiece(); + DrlgInitL2Vals(); DRLG_SetPC(); } diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 25e9a69a0..360ce8f73 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -856,7 +856,7 @@ static void InitL3Dungeon() } } -static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2) +static bool DrlgL3FillRoom(int x1, int y1, int x2, int y2) { if (x1 <= 1 || x2 >= 34 || y1 <= 1 || y2 >= 38) { return false; @@ -898,7 +898,7 @@ static bool DRLG_L3FillRoom(int x1, int y1, int x2, int y2) return true; } -static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) +static void DrlgL3CreateBlock(int x, int y, int obs, int dir) { int x1; int y1; @@ -965,24 +965,24 @@ static void DRLG_L3CreateBlock(int x, int y, int obs, int dir) y2 = y1 + blksizey; } - if (DRLG_L3FillRoom(x1, y1, x2, y2)) { + if (DrlgL3FillRoom(x1, y1, x2, y2)) { int contflag = GenerateRnd(4); if (contflag != 0 && dir != 2) { - DRLG_L3CreateBlock(x1, y1, blksizey, 0); + DrlgL3CreateBlock(x1, y1, blksizey, 0); } if (contflag != 0 && dir != 3) { - DRLG_L3CreateBlock(x2, y1, blksizex, 1); + DrlgL3CreateBlock(x2, y1, blksizex, 1); } if (contflag != 0 && dir != 0) { - DRLG_L3CreateBlock(x1, y2, blksizey, 2); + DrlgL3CreateBlock(x1, y2, blksizey, 2); } if (contflag != 0 && dir != 1) { - DRLG_L3CreateBlock(x1, y1, blksizex, 3); + DrlgL3CreateBlock(x1, y1, blksizex, 3); } } } -static void DRLG_L3FloorArea(int x1, int y1, int x2, int y2) +static void DrlgL3FloorArea(int x1, int y1, int x2, int y2) { for (int j = y1; j <= y2; j++) { for (int i = x1; i <= x2; i++) { @@ -991,7 +991,7 @@ static void DRLG_L3FloorArea(int x1, int y1, int x2, int y2) } } -static void DRLG_L3FillDiags() +static void DrlgL3FillDiags() { for (int j = 0; j < DMAXY - 1; j++) { for (int i = 0; i < DMAXX - 1; i++) { @@ -1014,7 +1014,7 @@ static void DRLG_L3FillDiags() } } -static void DRLG_L3FillSingles() +static void DrlgL3FillSingles() { for (int j = 1; j < DMAXY - 1; j++) { for (int i = 1; i < DMAXX - 1; i++) { @@ -1028,7 +1028,7 @@ static void DRLG_L3FillSingles() } } -static void DRLG_L3FillStraights() +static void DrlgL3FillStraights() { int xc; int yc; @@ -1111,7 +1111,7 @@ static void DRLG_L3FillStraights() } } -static void DRLG_L3Edges() +static void DrlgL3Edges() { for (int j = 0; j < DMAXY; j++) { dungeon[DMAXX - 1][j] = 0; @@ -1121,7 +1121,7 @@ static void DRLG_L3Edges() } } -static int DRLG_L3GetFloorArea() +static int DrlgL3GetFloorArea() { int gfa = 0; @@ -1134,7 +1134,7 @@ static int DRLG_L3GetFloorArea() return gfa; } -static void DRLG_L3MakeMegas() +static void DrlgL3MakeMegas() { for (int j = 0; j < DMAXY - 1; j++) { for (int i = 0; i < DMAXX - 1; i++) { @@ -1164,7 +1164,7 @@ static void DRLG_L3MakeMegas() } } -static void DRLG_L3River() +static void DrlgL3River() { int dir; int nodir; @@ -1415,9 +1415,9 @@ static void DRLG_L3River() } } -static bool DRLG_L3Spawn(int x, int y, int *totarea); +static bool DrlgL3Spawn(int x, int y, int *totarea); -static bool DRLG_L3SpawnEdge(int x, int y, int *totarea) +static bool DrlgL3SpawnEdge(int x, int y, int *totarea) { BYTE i; static BYTE spawntable[15] = { 0x00, 0x0A, 0x43, 0x05, 0x2c, 0x06, 0x09, 0x00, 0x00, 0x1c, 0x83, 0x06, 0x09, 0x0A, 0x05 }; @@ -1439,35 +1439,35 @@ static bool DRLG_L3SpawnEdge(int x, int y, int *totarea) dungeon[x][y] |= 0x80; *totarea += 1; - if ((spawntable[i] & 8) != 0 && DRLG_L3SpawnEdge(x, y - 1, totarea)) { + if ((spawntable[i] & 8) != 0 && DrlgL3SpawnEdge(x, y - 1, totarea)) { return true; } - if ((spawntable[i] & 4) != 0 && DRLG_L3SpawnEdge(x, y + 1, totarea)) { + if ((spawntable[i] & 4) != 0 && DrlgL3SpawnEdge(x, y + 1, totarea)) { return true; } - if ((spawntable[i] & 2) != 0 && DRLG_L3SpawnEdge(x + 1, y, totarea)) { + if ((spawntable[i] & 2) != 0 && DrlgL3SpawnEdge(x + 1, y, totarea)) { return true; } - if ((spawntable[i] & 1) != 0 && DRLG_L3SpawnEdge(x - 1, y, totarea)) { + if ((spawntable[i] & 1) != 0 && DrlgL3SpawnEdge(x - 1, y, totarea)) { return true; } - if ((spawntable[i] & 0x80) != 0 && DRLG_L3Spawn(x, y - 1, totarea)) { + if ((spawntable[i] & 0x80) != 0 && DrlgL3Spawn(x, y - 1, totarea)) { return true; } - if ((spawntable[i] & 0x40) != 0 && DRLG_L3Spawn(x, y + 1, totarea)) { + if ((spawntable[i] & 0x40) != 0 && DrlgL3Spawn(x, y + 1, totarea)) { return true; } - if ((spawntable[i] & 0x20) != 0 && DRLG_L3Spawn(x + 1, y, totarea)) { + if ((spawntable[i] & 0x20) != 0 && DrlgL3Spawn(x + 1, y, totarea)) { return true; } - if ((spawntable[i] & 0x10) != 0 && DRLG_L3Spawn(x - 1, y, totarea)) { + if ((spawntable[i] & 0x10) != 0 && DrlgL3Spawn(x - 1, y, totarea)) { return true; } return false; } -static bool DRLG_L3Spawn(int x, int y, int *totarea) +static bool DrlgL3Spawn(int x, int y, int *totarea) { BYTE i; static BYTE spawntable[15] = { 0x00, 0x0A, 0x03, 0x05, 0x0C, 0x06, 0x09, 0x00, 0x00, 0x0C, 0x03, 0x06, 0x09, 0x0A, 0x05 }; @@ -1490,29 +1490,29 @@ static bool DRLG_L3Spawn(int x, int y, int *totarea) *totarea += 1; if (i != 8) { - if ((spawntable[i] & 8) != 0 && DRLG_L3SpawnEdge(x, y - 1, totarea)) { + if ((spawntable[i] & 8) != 0 && DrlgL3SpawnEdge(x, y - 1, totarea)) { return true; } - if ((spawntable[i] & 4) != 0 && DRLG_L3SpawnEdge(x, y + 1, totarea)) { + if ((spawntable[i] & 4) != 0 && DrlgL3SpawnEdge(x, y + 1, totarea)) { return true; } - if ((spawntable[i] & 2) != 0 && DRLG_L3SpawnEdge(x + 1, y, totarea)) { + if ((spawntable[i] & 2) != 0 && DrlgL3SpawnEdge(x + 1, y, totarea)) { return true; } - if ((spawntable[i] & 1) != 0 && DRLG_L3SpawnEdge(x - 1, y, totarea)) { + if ((spawntable[i] & 1) != 0 && DrlgL3SpawnEdge(x - 1, y, totarea)) { return true; } } else { - if (DRLG_L3Spawn(x + 1, y, totarea)) { + if (DrlgL3Spawn(x + 1, y, totarea)) { return true; } - if (DRLG_L3Spawn(x - 1, y, totarea)) { + if (DrlgL3Spawn(x - 1, y, totarea)) { return true; } - if (DRLG_L3Spawn(x, y + 1, totarea)) { + if (DrlgL3Spawn(x, y + 1, totarea)) { return true; } - if (DRLG_L3Spawn(x, y - 1, totarea)) { + if (DrlgL3Spawn(x, y - 1, totarea)) { return true; } } @@ -1525,7 +1525,7 @@ static bool DRLG_L3Spawn(int x, int y, int *totarea) * an area of at most 40 tiles and disconnected from the map edge. * If it finds one, converts it to lava tiles and sets lavapool to true. */ -static void DRLG_L3Pool() +static void DrlgL3Pool() { constexpr uint8_t Poolsub[15] = { 0, 35, 26, 36, 25, 29, 34, 7, 33, 28, 27, 37, 32, 31, 30 }; @@ -1538,20 +1538,20 @@ static void DRLG_L3Pool() int totarea = 1; bool found = true; if (dunx + 1 < DMAXX) { - found = DRLG_L3Spawn(dunx + 1, duny, &totarea); + found = DrlgL3Spawn(dunx + 1, duny, &totarea); } if (dunx - 1 > 0 && !found) { - found = DRLG_L3Spawn(dunx - 1, duny, &totarea); + found = DrlgL3Spawn(dunx - 1, duny, &totarea); } else { found = true; } if (duny + 1 < DMAXY && !found) { - found = DRLG_L3Spawn(dunx, duny + 1, &totarea); + found = DrlgL3Spawn(dunx, duny + 1, &totarea); } else { found = true; } if (duny - 1 > 0 && !found) { - found = DRLG_L3Spawn(dunx, duny - 1, &totarea); + found = DrlgL3Spawn(dunx, duny - 1, &totarea); } else { found = true; } @@ -1576,7 +1576,7 @@ static void DRLG_L3Pool() } } -static void DRLG_L3PoolFix() +static void DrlgL3PoolFix() { for (int duny = 1; duny < DMAXY - 1; duny++) { // BUGFIX: Change '0' to '1' and 'DMAXY' to 'DMAXY - 1' (fixed) for (int dunx = 1; dunx < DMAXX - 1; dunx++) { // BUGFIX: Change '0' to '1' and 'DMAXX' to 'DMAXX - 1' (fixed) @@ -1598,7 +1598,7 @@ static void DRLG_L3PoolFix() } } -static bool DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) { int sx; int sy; @@ -1678,7 +1678,7 @@ static bool DRLG_L3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, return false; } -static void DRLG_L3PlaceRndSet(const BYTE *miniset, int rndper) +static void DrlgL3PlaceRndSet(const BYTE *miniset, int rndper) { int sw = miniset[0]; int sh = miniset[1]; @@ -1888,7 +1888,7 @@ void FenceDoorFix() } } -static void DRLG_L3Wood() +static void DrlgL3Wood() { for (int j = 1; j < DMAXY - 1; j++) { // BUGFIX: Change '0' to '1' (fixed) for (int i = 1; i < DMAXX - 1; i++) { // BUGFIX: Change '0' to '1' (fixed) @@ -2080,7 +2080,7 @@ static void DRLG_L3Wood() FenceDoorFix(); } -static bool DRLG_L3Anvil() +static bool DrlgL3Anvil() { int sw = L3ANVIL[0]; int sh = L3ANVIL[1]; @@ -2181,7 +2181,7 @@ static void FixL3HallofHeroes() } } -static void DRLG_L3LockRec(int x, int y) +static void DrlgL3LockRec(int x, int y) { if (!lockout[x][y]) { return; @@ -2189,10 +2189,10 @@ static void DRLG_L3LockRec(int x, int y) lockout[x][y] = false; lockoutcnt++; - DRLG_L3LockRec(x, y - 1); - DRLG_L3LockRec(x, y + 1); - DRLG_L3LockRec(x - 1, y); - DRLG_L3LockRec(x + 1, y); + DrlgL3LockRec(x, y - 1); + DrlgL3LockRec(x, y + 1); + DrlgL3LockRec(x - 1, y); + DrlgL3LockRec(x + 1, y); } bool DRLG_L3Lockout() @@ -2215,12 +2215,12 @@ bool DRLG_L3Lockout() } lockoutcnt = 0; - DRLG_L3LockRec(fx, fy); + DrlgL3LockRec(fx, fy); return t == lockoutcnt; } -static void DRLG_L3(lvl_entry entry) +static void DrlgL3(lvl_entry entry) { bool found; bool genok; @@ -2235,102 +2235,102 @@ static void DRLG_L3(lvl_entry entry) int y1 = GenerateRnd(20) + 10; int x2 = x1 + 2; int y2 = y1 + 2; - DRLG_L3FillRoom(x1, y1, x2, y2); - DRLG_L3CreateBlock(x1, y1, 2, 0); - DRLG_L3CreateBlock(x2, y1, 2, 1); - DRLG_L3CreateBlock(x1, y2, 2, 2); - DRLG_L3CreateBlock(x1, y1, 2, 3); + DrlgL3FillRoom(x1, y1, x2, y2); + DrlgL3CreateBlock(x1, y1, 2, 0); + DrlgL3CreateBlock(x2, y1, 2, 1); + DrlgL3CreateBlock(x1, y2, 2, 2); + DrlgL3CreateBlock(x1, y1, 2, 3); if (QuestStatus(Q_ANVIL)) { x1 = GenerateRnd(10) + 10; y1 = GenerateRnd(10) + 10; x2 = x1 + 12; y2 = y1 + 12; - DRLG_L3FloorArea(x1, y1, x2, y2); - } - DRLG_L3FillDiags(); - DRLG_L3FillSingles(); - DRLG_L3FillStraights(); - DRLG_L3FillDiags(); - DRLG_L3Edges(); - if (DRLG_L3GetFloorArea() >= 600) { + DrlgL3FloorArea(x1, y1, x2, y2); + } + DrlgL3FillDiags(); + DrlgL3FillSingles(); + DrlgL3FillStraights(); + DrlgL3FillDiags(); + DrlgL3Edges(); + if (DrlgL3GetFloorArea() >= 600) { found = DRLG_L3Lockout(); } else { found = false; } } while (!found); - DRLG_L3MakeMegas(); + DrlgL3MakeMegas(); if (entry == ENTRY_MAIN) { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, true, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, true, 0); } else { if (currlevel != 17) - genok = DRLG_L3PlaceMiniSet(L6UP, 1, 1, -1, -1, true, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, true, 0); else - genok = DRLG_L3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); } if (!genok) { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); } else { if (currlevel != 20) - genok = DRLG_L3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); } if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); } } } else if (entry == ENTRY_PREV) { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); } else { if (currlevel != 17) - genok = DRLG_L3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); else - genok = DRLG_L3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false, 6); } if (!genok) { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true, 1); ViewX += 2; ViewY -= 2; } else { if (currlevel != 20) { - genok = DRLG_L3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true, 1); ViewX += 2; ViewY -= 2; } } if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); } } } else { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); } else { if (currlevel != 17) - genok = DRLG_L3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); else - genok = DRLG_L3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); } if (!genok) { if (currlevel < 17) { - genok = DRLG_L3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); } else { if (currlevel != 20) - genok = DRLG_L3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); } if (!genok && currlevel == 9) { - genok = DRLG_L3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true, 6); } } } if (!genok && QuestStatus(Q_ANVIL)) { - genok = DRLG_L3Anvil(); + genok = DrlgL3Anvil(); } } while (genok); if (currlevel < 17) { - DRLG_L3Pool(); + DrlgL3Pool(); } else { if (drlg_l3_hive_rnd_piece(HivePattern41, 30)) lavapool++; @@ -2346,32 +2346,32 @@ static void DRLG_L3(lvl_entry entry) } while (lavapool == 0); if (currlevel < 17) - DRLG_L3PoolFix(); + DrlgL3PoolFix(); if (currlevel < 17) FixL3Warp(); if (currlevel < 17) { - DRLG_L3PlaceRndSet(L3ISLE1, 70); - DRLG_L3PlaceRndSet(L3ISLE2, 70); - DRLG_L3PlaceRndSet(L3ISLE3, 30); - DRLG_L3PlaceRndSet(L3ISLE4, 30); - DRLG_L3PlaceRndSet(L3ISLE1, 100); - DRLG_L3PlaceRndSet(L3ISLE2, 100); - DRLG_L3PlaceRndSet(L3ISLE5, 90); + DrlgL3PlaceRndSet(L3ISLE1, 70); + DrlgL3PlaceRndSet(L3ISLE2, 70); + DrlgL3PlaceRndSet(L3ISLE3, 30); + DrlgL3PlaceRndSet(L3ISLE4, 30); + DrlgL3PlaceRndSet(L3ISLE1, 100); + DrlgL3PlaceRndSet(L3ISLE2, 100); + DrlgL3PlaceRndSet(L3ISLE5, 90); } else { - DRLG_L3PlaceRndSet(L6ISLE1, 70); - DRLG_L3PlaceRndSet(L6ISLE2, 70); - DRLG_L3PlaceRndSet(L6ISLE3, 30); - DRLG_L3PlaceRndSet(L6ISLE4, 30); - DRLG_L3PlaceRndSet(L6ISLE1, 100); - DRLG_L3PlaceRndSet(L6ISLE2, 100); - DRLG_L3PlaceRndSet(L6ISLE5, 90); + DrlgL3PlaceRndSet(L6ISLE1, 70); + DrlgL3PlaceRndSet(L6ISLE2, 70); + DrlgL3PlaceRndSet(L6ISLE3, 30); + DrlgL3PlaceRndSet(L6ISLE4, 30); + DrlgL3PlaceRndSet(L6ISLE1, 100); + DrlgL3PlaceRndSet(L6ISLE2, 100); + DrlgL3PlaceRndSet(L6ISLE5, 90); } if (currlevel < 17) FixL3HallofHeroes(); if (currlevel < 17) - DRLG_L3River(); + DrlgL3River(); if (QuestStatus(Q_ANVIL)) { dungeon[setpc_x + 7][setpc_y + 5] = 7; @@ -2386,83 +2386,83 @@ static void DRLG_L3(lvl_entry entry) DRLG_PlaceThemeRooms(5, 10, 7, 0, false); if (currlevel < 17) { - DRLG_L3Wood(); - DRLG_L3PlaceRndSet(L3TITE1, 10); - DRLG_L3PlaceRndSet(L3TITE2, 10); - DRLG_L3PlaceRndSet(L3TITE3, 10); - DRLG_L3PlaceRndSet(L3TITE6, 20); - DRLG_L3PlaceRndSet(L3TITE7, 20); - DRLG_L3PlaceRndSet(L3TITE8, 20); - DRLG_L3PlaceRndSet(L3TITE9, 20); - DRLG_L3PlaceRndSet(L3TITE10, 20); - DRLG_L3PlaceRndSet(L3TITE11, 30); - DRLG_L3PlaceRndSet(L3TITE12, 20); - DRLG_L3PlaceRndSet(L3TITE13, 20); - DRLG_L3PlaceRndSet(L3CREV1, 30); - DRLG_L3PlaceRndSet(L3CREV2, 30); - DRLG_L3PlaceRndSet(L3CREV3, 30); - DRLG_L3PlaceRndSet(L3CREV4, 30); - DRLG_L3PlaceRndSet(L3CREV5, 30); - DRLG_L3PlaceRndSet(L3CREV6, 30); - DRLG_L3PlaceRndSet(L3CREV7, 30); - DRLG_L3PlaceRndSet(L3CREV8, 30); - DRLG_L3PlaceRndSet(L3CREV9, 30); - DRLG_L3PlaceRndSet(L3CREV10, 30); - DRLG_L3PlaceRndSet(L3CREV11, 30); - DRLG_L3PlaceRndSet(L3XTRA1, 25); - DRLG_L3PlaceRndSet(L3XTRA2, 25); - DRLG_L3PlaceRndSet(L3XTRA3, 25); - DRLG_L3PlaceRndSet(L3XTRA4, 25); - DRLG_L3PlaceRndSet(L3XTRA5, 25); + DrlgL3Wood(); + DrlgL3PlaceRndSet(L3TITE1, 10); + DrlgL3PlaceRndSet(L3TITE2, 10); + DrlgL3PlaceRndSet(L3TITE3, 10); + DrlgL3PlaceRndSet(L3TITE6, 20); + DrlgL3PlaceRndSet(L3TITE7, 20); + DrlgL3PlaceRndSet(L3TITE8, 20); + DrlgL3PlaceRndSet(L3TITE9, 20); + DrlgL3PlaceRndSet(L3TITE10, 20); + DrlgL3PlaceRndSet(L3TITE11, 30); + DrlgL3PlaceRndSet(L3TITE12, 20); + DrlgL3PlaceRndSet(L3TITE13, 20); + DrlgL3PlaceRndSet(L3CREV1, 30); + DrlgL3PlaceRndSet(L3CREV2, 30); + DrlgL3PlaceRndSet(L3CREV3, 30); + DrlgL3PlaceRndSet(L3CREV4, 30); + DrlgL3PlaceRndSet(L3CREV5, 30); + DrlgL3PlaceRndSet(L3CREV6, 30); + DrlgL3PlaceRndSet(L3CREV7, 30); + DrlgL3PlaceRndSet(L3CREV8, 30); + DrlgL3PlaceRndSet(L3CREV9, 30); + DrlgL3PlaceRndSet(L3CREV10, 30); + DrlgL3PlaceRndSet(L3CREV11, 30); + DrlgL3PlaceRndSet(L3XTRA1, 25); + DrlgL3PlaceRndSet(L3XTRA2, 25); + DrlgL3PlaceRndSet(L3XTRA3, 25); + DrlgL3PlaceRndSet(L3XTRA4, 25); + DrlgL3PlaceRndSet(L3XTRA5, 25); } else { - DRLG_L3PlaceRndSet(HivePattern1, 20); - DRLG_L3PlaceRndSet(HivePattern2, 20); - DRLG_L3PlaceRndSet(HivePattern3, 20); - DRLG_L3PlaceRndSet(HivePattern4, 20); - DRLG_L3PlaceRndSet(HivePattern29, 10); - DRLG_L3PlaceRndSet(HivePattern30, 15); - DRLG_L3PlaceRndSet(HivePattern31, 20); - DRLG_L3PlaceRndSet(HivePattern32, 25); - DRLG_L3PlaceRndSet(HivePattern33, 30); - DRLG_L3PlaceRndSet(HivePattern34, 35); - DRLG_L3PlaceRndSet(HivePattern35, 40); - DRLG_L3PlaceRndSet(HivePattern36, 45); - DRLG_L3PlaceRndSet(HivePattern37, 50); - DRLG_L3PlaceRndSet(HivePattern38, 55); - DRLG_L3PlaceRndSet(HivePattern38, 10); - DRLG_L3PlaceRndSet(HivePattern37, 15); - DRLG_L3PlaceRndSet(HivePattern36, 20); - DRLG_L3PlaceRndSet(HivePattern35, 25); - DRLG_L3PlaceRndSet(HivePattern34, 30); - DRLG_L3PlaceRndSet(HivePattern33, 35); - DRLG_L3PlaceRndSet(HivePattern32, 40); - DRLG_L3PlaceRndSet(HivePattern31, 45); - DRLG_L3PlaceRndSet(HivePattern30, 50); - DRLG_L3PlaceRndSet(HivePattern29, 55); - DRLG_L3PlaceRndSet(HivePattern9, 40); - DRLG_L3PlaceRndSet(HivePattern10, 45); - DRLG_L3PlaceRndSet(HivePattern5, 25); - DRLG_L3PlaceRndSet(HivePattern6, 25); - DRLG_L3PlaceRndSet(HivePattern7, 25); - DRLG_L3PlaceRndSet(HivePattern8, 25); - DRLG_L3PlaceRndSet(HivePattern11, 25); - DRLG_L3PlaceRndSet(HivePattern12, 25); - DRLG_L3PlaceRndSet(HivePattern13, 25); - DRLG_L3PlaceRndSet(HivePattern14, 25); - DRLG_L3PlaceRndSet(HivePattern15, 25); - DRLG_L3PlaceRndSet(HivePattern17, 25); - DRLG_L3PlaceRndSet(HivePattern18, 25); - DRLG_L3PlaceRndSet(HivePattern19, 25); - DRLG_L3PlaceRndSet(HivePattern20, 25); - DRLG_L3PlaceRndSet(HivePattern21, 25); - DRLG_L3PlaceRndSet(HivePattern23, 25); - DRLG_L3PlaceRndSet(HivePattern24, 25); - DRLG_L3PlaceRndSet(HivePattern25, 25); - DRLG_L3PlaceRndSet(HivePattern26, 25); - DRLG_L3PlaceRndSet(HivePattern16, 25); - DRLG_L3PlaceRndSet(HivePattern22, 25); - DRLG_L3PlaceRndSet(HivePattern27, 25); - DRLG_L3PlaceRndSet(HivePattern28, 25); + DrlgL3PlaceRndSet(HivePattern1, 20); + DrlgL3PlaceRndSet(HivePattern2, 20); + DrlgL3PlaceRndSet(HivePattern3, 20); + DrlgL3PlaceRndSet(HivePattern4, 20); + DrlgL3PlaceRndSet(HivePattern29, 10); + DrlgL3PlaceRndSet(HivePattern30, 15); + DrlgL3PlaceRndSet(HivePattern31, 20); + DrlgL3PlaceRndSet(HivePattern32, 25); + DrlgL3PlaceRndSet(HivePattern33, 30); + DrlgL3PlaceRndSet(HivePattern34, 35); + DrlgL3PlaceRndSet(HivePattern35, 40); + DrlgL3PlaceRndSet(HivePattern36, 45); + DrlgL3PlaceRndSet(HivePattern37, 50); + DrlgL3PlaceRndSet(HivePattern38, 55); + DrlgL3PlaceRndSet(HivePattern38, 10); + DrlgL3PlaceRndSet(HivePattern37, 15); + DrlgL3PlaceRndSet(HivePattern36, 20); + DrlgL3PlaceRndSet(HivePattern35, 25); + DrlgL3PlaceRndSet(HivePattern34, 30); + DrlgL3PlaceRndSet(HivePattern33, 35); + DrlgL3PlaceRndSet(HivePattern32, 40); + DrlgL3PlaceRndSet(HivePattern31, 45); + DrlgL3PlaceRndSet(HivePattern30, 50); + DrlgL3PlaceRndSet(HivePattern29, 55); + DrlgL3PlaceRndSet(HivePattern9, 40); + DrlgL3PlaceRndSet(HivePattern10, 45); + DrlgL3PlaceRndSet(HivePattern5, 25); + DrlgL3PlaceRndSet(HivePattern6, 25); + DrlgL3PlaceRndSet(HivePattern7, 25); + DrlgL3PlaceRndSet(HivePattern8, 25); + DrlgL3PlaceRndSet(HivePattern11, 25); + DrlgL3PlaceRndSet(HivePattern12, 25); + DrlgL3PlaceRndSet(HivePattern13, 25); + DrlgL3PlaceRndSet(HivePattern14, 25); + DrlgL3PlaceRndSet(HivePattern15, 25); + DrlgL3PlaceRndSet(HivePattern17, 25); + DrlgL3PlaceRndSet(HivePattern18, 25); + DrlgL3PlaceRndSet(HivePattern19, 25); + DrlgL3PlaceRndSet(HivePattern20, 25); + DrlgL3PlaceRndSet(HivePattern21, 25); + DrlgL3PlaceRndSet(HivePattern23, 25); + DrlgL3PlaceRndSet(HivePattern24, 25); + DrlgL3PlaceRndSet(HivePattern25, 25); + DrlgL3PlaceRndSet(HivePattern26, 25); + DrlgL3PlaceRndSet(HivePattern16, 25); + DrlgL3PlaceRndSet(HivePattern22, 25); + DrlgL3PlaceRndSet(HivePattern27, 25); + DrlgL3PlaceRndSet(HivePattern28, 25); } for (int j = 0; j < DMAXY; j++) { @@ -2474,7 +2474,7 @@ static void DRLG_L3(lvl_entry entry) DRLG_Init_Globals(); } -static void DRLG_L3Pass3() +static void DrlgL3Pass3() { DRLG_LPass3(8 - 1); } @@ -2488,8 +2488,8 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry) dmaxy = 96; DRLG_InitTrans(); DRLG_InitSetPC(); - DRLG_L3(entry); - DRLG_L3Pass3(); + DrlgL3(entry); + DrlgL3Pass3(); if (currlevel < 17) { for (int j = 0; j < MAXDUNY; j++) { @@ -2550,7 +2550,7 @@ void LoadL3Dungeon(const char *path, int vx, int vy) } } - DRLG_L3Pass3(); + DrlgL3Pass3(); DRLG_Init_Globals(); ViewX = vx; diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 312dee9f3..78a8744f8 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -153,7 +153,7 @@ const BYTE L4BTYPES[140] = { } // namespace -static void DRLG_L4Shadows() +static void DrlgL4Shadows() { for (int y = 1; y < DMAXY; y++) { for (int x = 1; x < DMAXY; x++) { @@ -742,7 +742,7 @@ static void L4tileFix() } } -static void DRLG_L4Subs() +static void DrlgL4Subs() { for (int y = 0; y < DMAXY; y++) { for (int x = 0; x < DMAXX; x++) { @@ -824,7 +824,7 @@ static void L4makeDungeon() } } -static void uShape() +static void UShape() { for (int j = 19; j >= 0; j--) { for (int i = 19; i >= 0; i--) { @@ -1094,7 +1094,7 @@ void DRLG_LoadDiabQuads(bool preflag) } } -static bool DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) { int sx; int sy; @@ -1185,7 +1185,7 @@ static bool DRLG_L4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, #pragma GCC optimize("O0") #endif -static void DRLG_L4FTVR(int i, int j, int x, int y, int d) +static void DrlgL4FTransparencyValueR(int i, int j, int x, int y, int d) { if (dTransVal[x][y] != 0 || dungeon[i][j] != 6) { if (d == 1) { @@ -1221,25 +1221,25 @@ static void DRLG_L4FTVR(int i, int j, int x, int y, int d) dTransVal[x + 1][y] = TransVal; dTransVal[x][y + 1] = TransVal; dTransVal[x + 1][y + 1] = TransVal; - DRLG_L4FTVR(i + 1, j, x + 2, y, 1); - DRLG_L4FTVR(i - 1, j, x - 2, y, 2); - DRLG_L4FTVR(i, j + 1, x, y + 2, 3); - DRLG_L4FTVR(i, j - 1, x, y - 2, 4); - DRLG_L4FTVR(i - 1, j - 1, x - 2, y - 2, 5); - DRLG_L4FTVR(i + 1, j - 1, x + 2, y - 2, 6); - DRLG_L4FTVR(i - 1, j + 1, x - 2, y + 2, 7); - DRLG_L4FTVR(i + 1, j + 1, x + 2, y + 2, 8); + DrlgL4FTransparencyValueR(i + 1, j, x + 2, y, 1); + DrlgL4FTransparencyValueR(i - 1, j, x - 2, y, 2); + DrlgL4FTransparencyValueR(i, j + 1, x, y + 2, 3); + DrlgL4FTransparencyValueR(i, j - 1, x, y - 2, 4); + DrlgL4FTransparencyValueR(i - 1, j - 1, x - 2, y - 2, 5); + DrlgL4FTransparencyValueR(i + 1, j - 1, x + 2, y - 2, 6); + DrlgL4FTransparencyValueR(i - 1, j + 1, x - 2, y + 2, 7); + DrlgL4FTransparencyValueR(i + 1, j + 1, x + 2, y + 2, 8); } } -static void DRLG_L4FloodTVal() +static void DrlgL4FloodTVal() { int yy = 16; for (int j = 0; j < DMAXY; j++) { int xx = 16; for (int i = 0; i < DMAXX; i++) { if (dungeon[i][j] == 6 && dTransVal[xx][yy] == 0) { - DRLG_L4FTVR(i, j, xx, yy, 0); + DrlgL4FTransparencyValueR(i, j, xx, yy, 0); TransVal++; } xx += 2; @@ -1282,7 +1282,7 @@ bool IsDLLWall(char dd) return false; } -static void DRLG_L4TransFix() +static void DrlgL4TransFix() { int yy = 16; for (int j = 0; j < DMAXY; j++) { @@ -1323,7 +1323,7 @@ static void DRLG_L4TransFix() } } -static void DRLG_L4Corners() +static void DrlgL4Corners() { for (int j = 1; j < DMAXY - 1; j++) { for (int i = 1; i < DMAXX - 1; i++) { @@ -1359,7 +1359,7 @@ void DRLG_L4GeneralFix() } } -static void DRLG_L4(lvl_entry entry) +static void DrlgL4(lvl_entry entry) { int ar; bool doneflag; @@ -1372,7 +1372,7 @@ static void DRLG_L4(lvl_entry entry) L4FixRim(); ar = GetArea(); if (ar >= 173) { - uShape(); + UShape(); } } while (ar < 173); L4makeDungeon(); @@ -1389,8 +1389,8 @@ static void DRLG_L4(lvl_entry entry) } } L4AddWall(); - DRLG_L4FloodTVal(); - DRLG_L4TransFix(); + DrlgL4FloodTVal(); + DrlgL4TransFix(); if (setloadflag) { DRLG_L4SetSPRoom(SP4x1, SP4y1); } @@ -1399,72 +1399,72 @@ static void DRLG_L4(lvl_entry entry) } if (QuestStatus(Q_WARLORD)) { if (entry == ENTRY_MAIN) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); } ViewX++; } else if (entry == ENTRY_PREV) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); } ViewX = 2 * setpc_x + 22; ViewY = 2 * setpc_y + 22; } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); } ViewX++; } } else if (currlevel != 15) { if (entry == ENTRY_MAIN) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); } if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); } ViewX++; } else if (entry == ENTRY_PREV) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true, 1); } if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); } ViewY++; } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag && currlevel != 16) { - doneflag = DRLG_L4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); } if (doneflag && currlevel == 13) { - doneflag = DRLG_L4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); } ViewX++; } } else { if (entry == ENTRY_MAIN) { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); if (doneflag) { if (!gbIsMultiplayer && quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false, 1); } else { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false, 1); } } ViewX++; } else { - doneflag = DRLG_L4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); if (doneflag) { if (!gbIsMultiplayer && quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true, 1); } else { - doneflag = DRLG_L4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true, 1); } } ViewY++; @@ -1478,9 +1478,9 @@ static void DRLG_L4(lvl_entry entry) DRLG_PlaceThemeRooms(7, 10, 6, 8, true); } - DRLG_L4Shadows(); - DRLG_L4Corners(); - DRLG_L4Subs(); + DrlgL4Shadows(); + DrlgL4Corners(); + DrlgL4Subs(); DRLG_Init_Globals(); if (QuestStatus(Q_WARLORD)) { @@ -1515,7 +1515,7 @@ static void DRLG_L4(lvl_entry entry) } } -static void DRLG_L4Pass3() +static void DrlgL4Pass3() { DRLG_LPass3(30 - 1); } @@ -1534,8 +1534,8 @@ void CreateL4Dungeon(uint32_t rseed, lvl_entry entry) DRLG_InitSetPC(); DRLG_LoadL4SP(); - DRLG_L4(entry); - DRLG_L4Pass3(); + DrlgL4(entry); + DrlgL4Pass3(); DRLG_FreeL4SP(); DRLG_SetPC(); } @@ -1557,7 +1557,7 @@ void LoadL4Dungeon(const char *path, int vx, int vy) ViewX = vx; ViewY = vy; - DRLG_L4Pass3(); + DrlgL4Pass3(); DRLG_Init_Globals(); SetMapMonsters(dunData.get(), { 0, 0 }); diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 1ce356d15..4f0ea29fa 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -25,7 +25,7 @@ namespace devilution { #define INDEX_ENTRIES 2048 -// Amiga cannot seekp beyond EOF. +// Amiga cannot Seekp beyond EOF. // See https://github.com/bebbo/libnix/issues/30 #ifndef __AMIGA__ #define CAN_SEEKP_BEYOND_EOF @@ -105,49 +105,49 @@ public: return s_ != nullptr; } - bool seekg(std::streampos pos) + bool Seekg(std::streampos pos) { s_->seekg(pos); return CheckError("seekg(%" PRIuMAX ")", static_cast(pos)); } - bool seekg(std::streamoff pos, std::ios::seekdir dir) + bool Seekg(std::streamoff pos, std::ios::seekdir dir) { s_->seekg(pos, dir); return CheckError("seekg(%" PRIdMAX ", %s)", static_cast(pos), DirToString(dir)); } - bool seekp(std::streampos pos) + bool Seekp(std::streampos pos) { s_->seekp(pos); return CheckError("seekp(%" PRIuMAX ")", static_cast(pos)); } - bool seekp(std::streamoff pos, std::ios::seekdir dir) + bool Seekp(std::streamoff pos, std::ios::seekdir dir) { s_->seekp(pos, dir); return CheckError("seekp(%" PRIdMAX ", %s)", static_cast(pos), DirToString(dir)); } - bool tellg(std::streampos *result) + bool Tellg(std::streampos *result) { *result = s_->tellg(); return CheckError("tellg() = %" PRIuMAX, static_cast(*result)); } - bool tellp(std::streampos *result) + bool Tellp(std::streampos *result) { *result = s_->tellp(); return CheckError("tellp() = %" PRIuMAX, static_cast(*result)); } - bool write(const char *data, std::streamsize size) + bool Write(const char *data, std::streamsize size) { s_->write(data, size); return CheckError("write(data, %" PRIuMAX ")", static_cast(size)); } - bool read(char *out, std::streamsize size) + bool Read(char *out, std::streamsize size) { s_->read(out, size); return CheckError("read(out, %" PRIuMAX ")", static_cast(size)); @@ -232,7 +232,7 @@ struct Archive { #endif bool result = true; - if (modified && !(stream.seekp(0, std::ios::beg) && WriteHeaderAndTables())) + if (modified && !(stream.Seekp(0, std::ios::beg) && WriteHeaderAndTables())) result = false; stream.Close(); if (modified && result && size != 0) { @@ -277,13 +277,13 @@ private: fhdr.hashcount = SDL_SwapLE32(INDEX_ENTRIES); fhdr.blockcount = SDL_SwapLE32(INDEX_ENTRIES); - return stream.write(reinterpret_cast(&fhdr), sizeof(fhdr)); + return stream.Write(reinterpret_cast(&fhdr), sizeof(fhdr)); } bool WriteBlockTable() { Encrypt((DWORD *)sgpBlockTbl, BlockEntrySize, Hash("(block table)", 3)); - const bool success = stream.write(reinterpret_cast(sgpBlockTbl), BlockEntrySize); + const bool success = stream.Write(reinterpret_cast(sgpBlockTbl), BlockEntrySize); Decrypt((DWORD *)sgpBlockTbl, BlockEntrySize, Hash("(block table)", 3)); return success; } @@ -291,7 +291,7 @@ private: bool WriteHashTable() { Encrypt((DWORD *)sgpHashTbl, HashEntrySize, Hash("(hash table)", 3)); - const bool success = stream.write(reinterpret_cast(sgpHashTbl), HashEntrySize); + const bool success = stream.Write(reinterpret_cast(sgpHashTbl), HashEntrySize); Decrypt((DWORD *)sgpHashTbl, HashEntrySize, Hash("(hash table)", 3)); return success; } @@ -340,7 +340,7 @@ bool ReadMPQHeader(Archive *archive, _FILEHEADER *hdr) { const bool has_hdr = archive->size >= sizeof(*hdr); if (has_hdr) { - if (!archive->stream.read(reinterpret_cast(hdr), sizeof(*hdr))) + if (!archive->stream.Read(reinterpret_cast(hdr), sizeof(*hdr))) return false; ByteSwapHdr(hdr); } @@ -350,9 +350,7 @@ bool ReadMPQHeader(Archive *archive, _FILEHEADER *hdr) return true; } -} // namespace - -static _BLOCKENTRY *mpqapi_new_block(int *block_index) +_BLOCKENTRY *NewBlock(int *block_index) { _BLOCKENTRY *blockEntry = cur_archive.sgpBlockTbl; @@ -375,7 +373,7 @@ static _BLOCKENTRY *mpqapi_new_block(int *block_index) app_fatal("Out of free block entries"); } -void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) +void AllocBlock(uint32_t block_offset, uint32_t block_size) { _BLOCKENTRY *block; int i; @@ -388,13 +386,13 @@ void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) block_offset = block->offset; block_size += block->sizealloc; memset(block, 0, sizeof(_BLOCKENTRY)); - mpqapi_alloc_block(block_offset, block_size); + AllocBlock(block_offset, block_size); return; } if (block_offset + block_size == block->offset) { block_size += block->sizealloc; memset(block, 0, sizeof(_BLOCKENTRY)); - mpqapi_alloc_block(block_offset, block_size); + AllocBlock(block_offset, block_size); return; } } @@ -406,7 +404,7 @@ void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) if (block_offset + block_size == cur_archive.size) { cur_archive.size = block_offset; } else { - block = mpqapi_new_block(nullptr); + block = NewBlock(nullptr); block->offset = block_offset; block->sizealloc = block_size; block->sizefile = 0; @@ -414,7 +412,7 @@ void mpqapi_alloc_block(uint32_t block_offset, uint32_t block_size) } } -int mpqapi_find_free_block(uint32_t size, uint32_t *block_size) +int FindFreeBlock(uint32_t size, uint32_t *block_size) { int result; @@ -446,7 +444,7 @@ int mpqapi_find_free_block(uint32_t size, uint32_t *block_size) return result; } -static int mpqapi_get_hash_index(int index, uint32_t hash_a, uint32_t hash_b) +int GetHashIndex(int index, uint32_t hash_a, uint32_t hash_b) { int i = INDEX_ENTRIES; for (int idx = index & 0x7FF; cur_archive.sgpHashTbl[idx].block != -1; idx = (idx + 1) & 0x7FF) { @@ -465,43 +463,17 @@ static int mpqapi_get_hash_index(int index, uint32_t hash_a, uint32_t hash_b) return -1; } -static int FetchHandle(const char *pszName) +int FetchHandle(const char *pszName) { - return mpqapi_get_hash_index(Hash(pszName, 0), Hash(pszName, 1), Hash(pszName, 2)); -} - -void mpqapi_remove_hash_entry(const char *pszName) -{ - int hIdx = FetchHandle(pszName); - if (hIdx == -1) { - return; - } - - _HASHENTRY *pHashTbl = &cur_archive.sgpHashTbl[hIdx]; - _BLOCKENTRY *blockEntry = &cur_archive.sgpBlockTbl[pHashTbl->block]; - pHashTbl->block = -2; - int block_offset = blockEntry->offset; - int 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)(uint8_t, char *)) -{ - char pszFileName[MAX_PATH]; - - for (uint8_t i = 0; fnGetName(i, pszFileName); i++) { - mpqapi_remove_hash_entry(pszFileName); - } + return GetHashIndex(Hash(pszName, 0), Hash(pszName, 1), Hash(pszName, 2)); } -static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int block_index) +_BLOCKENTRY *AddFile(const char *pszName, _BLOCKENTRY *pBlk, int block_index) { uint32_t h1 = Hash(pszName, 0); uint32_t h2 = Hash(pszName, 1); uint32_t h3 = Hash(pszName, 2); - if (mpqapi_get_hash_index(h1, h2, h3) != -1) + if (GetHashIndex(h1, h2, h3) != -1) app_fatal("Hash collision between \"%s\" and existing file\n", pszName); int hIdx = h1 & 0x7FF; @@ -517,7 +489,7 @@ static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int app_fatal("Out of hash space"); if (pBlk == nullptr) - pBlk = mpqapi_new_block(&block_index); + pBlk = NewBlock(&block_index); cur_archive.sgpHashTbl[hIdx].hashcheck[0] = h2; cur_archive.sgpHashTbl[hIdx].hashcheck[1] = h3; @@ -527,7 +499,7 @@ static _BLOCKENTRY *mpqapi_add_file(const char *pszName, _BLOCKENTRY *pBlk, int return pBlk; } -static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, size_t dwLen, _BLOCKENTRY *pBlk) +bool WriteFileContents(const char *pszName, const byte *pbData, size_t dwLen, _BLOCKENTRY *pBlk) { const char *tmp; while ((tmp = strchr(pszName, ':')) != nullptr) @@ -539,7 +511,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, constexpr size_t SectorSize = 4096; const uint32_t num_sectors = (dwLen + (SectorSize - 1)) / SectorSize; const uint32_t offset_table_bytesize = sizeof(uint32_t) * (num_sectors + 1); - pBlk->offset = mpqapi_find_free_block(dwLen + offset_table_bytesize, &pBlk->sizealloc); + pBlk->offset = FindFreeBlock(dwLen + offset_table_bytesize, &pBlk->sizealloc); pBlk->sizefile = dwLen; pBlk->flags = 0x80000100; @@ -549,24 +521,24 @@ static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, std::unique_ptr sectoroffsettable { new uint32_t[num_sectors + 1] }; #ifdef CAN_SEEKP_BEYOND_EOF - if (!cur_archive.stream.seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) + if (!cur_archive.stream.Seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) return false; #else - // Ensure we do not seekp beyond EOF by filling the missing space. + // Ensure we do not Seekp beyond EOF by filling the missing space. std::streampos stream_end; - if (!cur_archive.stream.seekp(0, std::ios::end) || !cur_archive.stream.tellp(&stream_end)) + if (!cur_archive.stream.Seekp(0, std::ios::end) || !cur_archive.stream.Tellp(&stream_end)) return false; const std::uintmax_t cur_size = stream_end - cur_archive.stream_begin; if (cur_size < pBlk->offset + offset_table_bytesize) { if (cur_size < pBlk->offset) { std::unique_ptr filler { new char[pBlk->offset - cur_size] }; - if (!cur_archive.stream.write(filler.get(), pBlk->offset - cur_size)) + if (!cur_archive.stream.Write(filler.get(), pBlk->offset - cur_size)) return false; } - if (!cur_archive.stream.write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) + if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) return false; } else { - if (!cur_archive.stream.seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) + if (!cur_archive.stream.Seekp(pBlk->offset + offset_table_bytesize, std::ios::beg)) return false; } #endif @@ -579,7 +551,7 @@ static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, memcpy(mpq_buf, pbData, len); pbData += len; len = PkwareCompress(mpq_buf, len); - if (!cur_archive.stream.write((char *)mpq_buf, len)) + if (!cur_archive.stream.Write((char *)mpq_buf, len)) return false; sectoroffsettable[cur_sector++] = SDL_SwapLE32(destsize); destsize += len; // compressed length @@ -590,31 +562,59 @@ static bool mpqapi_write_file_contents(const char *pszName, const byte *pbData, } sectoroffsettable[num_sectors] = SDL_SwapLE32(destsize); - if (!cur_archive.stream.seekp(pBlk->offset, std::ios::beg)) + if (!cur_archive.stream.Seekp(pBlk->offset, std::ios::beg)) return false; - if (!cur_archive.stream.write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) + if (!cur_archive.stream.Write(reinterpret_cast(sectoroffsettable.get()), offset_table_bytesize)) return false; - if (!cur_archive.stream.seekp(destsize - offset_table_bytesize, std::ios::cur)) + if (!cur_archive.stream.Seekp(destsize - offset_table_bytesize, std::ios::cur)) return false; if (destsize < pBlk->sizealloc) { const uint32_t block_size = pBlk->sizealloc - destsize; if (block_size >= 1024) { pBlk->sizealloc = destsize; - mpqapi_alloc_block(pBlk->sizealloc + pBlk->offset, block_size); + AllocBlock(pBlk->sizealloc + pBlk->offset, block_size); } } return true; } +} // namespace + +void mpqapi_remove_hash_entry(const char *pszName) +{ + int hIdx = FetchHandle(pszName); + if (hIdx == -1) { + return; + } + + _HASHENTRY *pHashTbl = &cur_archive.sgpHashTbl[hIdx]; + _BLOCKENTRY *blockEntry = &cur_archive.sgpBlockTbl[pHashTbl->block]; + pHashTbl->block = -2; + int block_offset = blockEntry->offset; + int block_size = blockEntry->sizealloc; + memset(blockEntry, 0, sizeof(*blockEntry)); + AllocBlock(block_offset, block_size); + cur_archive.modified = true; +} + +void mpqapi_remove_hash_entries(bool (*fnGetName)(uint8_t, char *)) +{ + char pszFileName[MAX_PATH]; + + for (uint8_t i = 0; fnGetName(i, pszFileName); i++) { + mpqapi_remove_hash_entry(pszFileName); + } +} + bool mpqapi_write_file(const char *pszName, const byte *pbData, size_t dwLen) { _BLOCKENTRY *blockEntry; cur_archive.modified = true; mpqapi_remove_hash_entry(pszName); - blockEntry = mpqapi_add_file(pszName, nullptr, 0); - if (!mpqapi_write_file_contents(pszName, pbData, dwLen, blockEntry)) { + blockEntry = AddFile(pszName, nullptr, 0); + if (!WriteFileContents(pszName, pbData, dwLen, blockEntry)) { mpqapi_remove_hash_entry(pszName); return false; } @@ -632,7 +632,7 @@ void mpqapi_rename(char *pszOld, char *pszNew) int block = hashEntry->block; _BLOCKENTRY *blockEntry = &cur_archive.sgpBlockTbl[block]; hashEntry->block = -2; - mpqapi_add_file(pszNew, blockEntry, block); + AddFile(pszNew, blockEntry, block); cur_archive.modified = true; } @@ -660,7 +660,7 @@ bool OpenMPQ(const char *pszArchive) cur_archive.sgpBlockTbl = new _BLOCKENTRY[BlockEntrySize / sizeof(_BLOCKENTRY)]; std::memset(cur_archive.sgpBlockTbl, 0, BlockEntrySize); if (fhdr.blockcount > 0) { - if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpBlockTbl), BlockEntrySize)) + if (!cur_archive.stream.Read(reinterpret_cast(cur_archive.sgpBlockTbl), BlockEntrySize)) goto on_error; key = Hash("(block table)", 3); Decrypt((DWORD *)cur_archive.sgpBlockTbl, BlockEntrySize, key); @@ -668,21 +668,21 @@ bool OpenMPQ(const char *pszArchive) cur_archive.sgpHashTbl = new _HASHENTRY[HashEntrySize / sizeof(_HASHENTRY)]; std::memset(cur_archive.sgpHashTbl, 255, HashEntrySize); if (fhdr.hashcount > 0) { - if (!cur_archive.stream.read(reinterpret_cast(cur_archive.sgpHashTbl), HashEntrySize)) + if (!cur_archive.stream.Read(reinterpret_cast(cur_archive.sgpHashTbl), HashEntrySize)) goto on_error; key = Hash("(hash table)", 3); Decrypt((DWORD *)cur_archive.sgpHashTbl, HashEntrySize, key); } #ifndef CAN_SEEKP_BEYOND_EOF - if (!cur_archive.stream.seekp(0, std::ios::beg)) + if (!cur_archive.stream.Seekp(0, std::ios::beg)) goto on_error; // Memorize stream begin, we'll need it for calculations later. - if (!cur_archive.stream.tellp(&cur_archive.stream_begin)) + if (!cur_archive.stream.Tellp(&cur_archive.stream_begin)) goto on_error; - // Write garbage header and tables because some platforms cannot `seekp` beyond EOF. + // Write garbage header and tables because some platforms cannot `Seekp` beyond EOF. // The data is incorrect at this point, it will be overwritten on Close. if (!cur_archive.exists) cur_archive.WriteHeaderAndTables(); diff --git a/Source/multi.cpp b/Source/multi.cpp index 724f8c85c..e9f191a2b 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -66,13 +66,15 @@ const event_type EventTypes[3] = { EVENT_TYPE_PLAYER_MESSAGE }; -static void buffer_init(TBuffer *pBuf) +namespace { + +void BufferInit(TBuffer *pBuf) { pBuf->dwNextWriteOffset = 0; pBuf->bData[0] = byte { 0 }; } -static void multi_copy_packet(TBuffer *buf, byte *packet, uint8_t size) +void CopyPacket(TBuffer *buf, byte *packet, uint8_t size) { if (buf->dwNextWriteOffset + size + 2 > 0x1000) { return; @@ -86,7 +88,7 @@ static void multi_copy_packet(TBuffer *buf, byte *packet, uint8_t size) p[size] = byte { 0 }; } -static byte *multi_recv_packet(TBuffer *pBuf, byte *body, size_t *size) +byte *ReceivePacket(TBuffer *pBuf, byte *body, size_t *size) { if (pBuf->dwNextWriteOffset != 0) { byte *src_ptr = pBuf->bData; @@ -109,7 +111,7 @@ static byte *multi_recv_packet(TBuffer *pBuf, byte *body, size_t *size) return body; } -static void NetRecvPlrData(TPkt *pkt) +void NetReceivePlayerData(TPkt *pkt) { const Point target = plr[myplr].GetTargetPosition(); @@ -125,72 +127,18 @@ static void NetRecvPlrData(TPkt *pkt) pkt->hdr.bdex = plr[myplr]._pBaseDex; } -void multi_msg_add(byte *pbMsg, BYTE bLen) -{ - if (pbMsg != nullptr && bLen != 0) { - tmsg_add(pbMsg, bLen); - } -} - -static void multi_send_packet(int playerId, void *packet, BYTE dwSize) +void SendPacket(int playerId, void *packet, BYTE dwSize) { TPkt pkt; - NetRecvPlrData(&pkt); + NetReceivePlayerData(&pkt); pkt.hdr.wLen = dwSize + sizeof(pkt.hdr); memcpy(pkt.body, packet, dwSize); if (!SNetSendMessage(playerId, &pkt.hdr, pkt.hdr.wLen)) nthread_terminate_game("SNetSendMessage0"); } -void NetSendLoPri(int playerId, byte *pbMsg, BYTE bLen) -{ - if (pbMsg != nullptr && bLen != 0) { - multi_copy_packet(&sgLoPriBuf, pbMsg, bLen); - multi_send_packet(playerId, pbMsg, bLen); - } -} - -void NetSendHiPri(int playerId, byte *pbMsg, BYTE bLen) -{ - if (pbMsg != nullptr && bLen != 0) { - multi_copy_packet(&sgHiPriBuf, pbMsg, bLen); - multi_send_packet(playerId, pbMsg, bLen); - } - if (!gbShouldValidatePackage) { - gbShouldValidatePackage = true; - TPkt pkt; - NetRecvPlrData(&pkt); - size_t size = gdwNormalMsgSize - sizeof(TPktHdr); - byte *hipri_body = multi_recv_packet(&sgHiPriBuf, pkt.body, &size); - byte *lowpri_body = multi_recv_packet(&sgLoPriBuf, hipri_body, &size); - size = sync_all_monsters(lowpri_body, size); - size_t len = gdwNormalMsgSize - size; - pkt.hdr.wLen = len; - if (!SNetSendMessage(-2, &pkt.hdr, len)) - nthread_terminate_game("SNetSendMessage"); - } -} - -void multi_send_msg_packet(uint32_t pmask, byte *src, BYTE len) -{ - TPkt pkt; - NetRecvPlrData(&pkt); - size_t t = len + sizeof(pkt.hdr); - pkt.hdr.wLen = t; - memcpy(pkt.body, src, len); - size_t p = 0; - for (size_t v = 1; p < MAX_PLRS; p++, v <<= 1) { - if ((v & pmask) != 0) { - if (!SNetSendMessage(p, &pkt.hdr, t) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) { - nthread_terminate_game("SNetSendMessage"); - return; - } - } - } -} - -static void multi_mon_seeds() +void MonsterSeeds() { sgdwGameLoops++; uint32_t l = (sgdwGameLoops >> 8) | (sgdwGameLoops << 24); // _rotr(sgdwGameLoops, 8) @@ -198,7 +146,7 @@ static void multi_mon_seeds() monster[i]._mAISeed = l + i; } -static void multi_handle_turn_upper_bit(int pnum) +void HandleTurnUpperBit(int pnum) { int i; @@ -214,13 +162,11 @@ static void multi_handle_turn_upper_bit(int pnum) } } -static void multi_parse_turn(int pnum, uint32_t turn) +void ParseTurn(int pnum, uint32_t turn) { - DWORD absTurns; - if ((turn & 0x80000000) != 0) - multi_handle_turn_upper_bit(pnum); - absTurns = turn & 0x7FFFFFFF; + HandleTurnUpperBit(pnum); + uint32_t absTurns = turn & 0x7FFFFFFF; if (sgbSentThisCycle < gdwTurnsInTransit + absTurns) { if (absTurns >= 0x7FFFFFFF) absTurns &= 0xFFFF; @@ -229,58 +175,44 @@ static void multi_parse_turn(int pnum, uint32_t turn) } } -void multi_msg_countdown() +void PlayerLeftMsg(int pnum, bool left) { - int i; - - for (i = 0; i < MAX_PLRS; i++) { - if ((player_state[i] & PS_TURN_ARRIVED) != 0) { - if (gdwMsgLenTbl[i] == 4) - multi_parse_turn(i, *(DWORD *)glpMsgTbl[i]); - } + if (!plr[pnum].plractive) { + return; } -} -static void multi_player_left_msg(int pnum, bool left) -{ - const char *pszFmt; - - if (plr[pnum].plractive) { - RemovePlrFromMap(pnum); - RemovePortalMissile(pnum); - DeactivatePortal(pnum); - delta_close_portal(pnum); - RemovePlrMissiles(pnum); - if (left) { - pszFmt = _("Player '{:s}' just left the game"); - switch (sgdwPlayerLeftReasonTbl[pnum]) { - case LEAVE_ENDING: - pszFmt = _("Player '{:s}' killed Diablo and left the game!"); - gbSomebodyWonGameKludge = true; - break; - case LEAVE_DROP: - pszFmt = _("Player '{:s}' dropped due to timeout"); - break; - } - EventPlrMsg(fmt::format(pszFmt, plr[pnum]._pName).c_str()); + RemovePlrFromMap(pnum); + RemovePortalMissile(pnum); + DeactivatePortal(pnum); + delta_close_portal(pnum); + RemovePlrMissiles(pnum); + if (left) { + const char *pszFmt = _("Player '{:s}' just left the game"); + switch (sgdwPlayerLeftReasonTbl[pnum]) { + case LEAVE_ENDING: + pszFmt = _("Player '{:s}' killed Diablo and left the game!"); + gbSomebodyWonGameKludge = true; + break; + case LEAVE_DROP: + pszFmt = _("Player '{:s}' dropped due to timeout"); + break; } - plr[pnum].plractive = false; - plr[pnum]._pName[0] = '\0'; - ResetPlayerGFX(plr[pnum]); - gbActivePlayers--; + EventPlrMsg(fmt::format(pszFmt, plr[pnum]._pName).c_str()); } + plr[pnum].plractive = false; + plr[pnum]._pName[0] = '\0'; + ResetPlayerGFX(plr[pnum]); + gbActivePlayers--; } -static void multi_clear_left_tbl() +void ClearPlayerLeftState() { - int i; - - for (i = 0; i < MAX_PLRS; i++) { + for (int i = 0; i < MAX_PLRS; i++) { if (sgbPlayerLeftGameTbl[i]) { if (gbBufferMsgs == 1) msg_send_drop_pkt(i, sgdwPlayerLeftReasonTbl[i]); else - multi_player_left_msg(i, true); + PlayerLeftMsg(i, true); sgbPlayerLeftGameTbl[i] = false; sgdwPlayerLeftReasonTbl[i] = 0; @@ -288,31 +220,16 @@ static void multi_clear_left_tbl() } } -void multi_player_left(int pnum, int reason) -{ - sgbPlayerLeftGameTbl[pnum] = true; - sgdwPlayerLeftReasonTbl[pnum] = reason; - multi_clear_left_tbl(); -} - -void multi_net_ping() +void CheckDropPlayer() { - sgbTimeout = true; - sglTimeoutStart = SDL_GetTicks(); -} - -static void multi_check_drop_player() -{ - int i; - - for (i = 0; i < MAX_PLRS; i++) { + for (int i = 0; i < MAX_PLRS; i++) { if ((player_state[i] & PS_ACTIVE) == 0 && (player_state[i] & PS_CONNECTED) != 0) { SNetDropPlayer(i, LEAVE_DROP); } } } -static void multi_begin_timeout() +void BeginTimeout() { if (!sgbTimeout) { return; @@ -363,27 +280,275 @@ static void multi_begin_timeout() if (nLowestPlayer != nLowestActive) { gbGameDestroyed = true; } else if (nLowestActive == myplr) { - multi_check_drop_player(); + CheckDropPlayer(); } } else if (nLowestActive == myplr) { - multi_check_drop_player(); + CheckDropPlayer(); } } +void HandleAllPackets(int pnum, byte *pData, int nSize) +{ + while (nSize != 0) { + int nLen = ParseCmd(pnum, (TCmd *)pData); + if (nLen == 0) { + break; + } + pData += nLen; + nSize -= nLen; + } +} + +void ProcessTmsgs() +{ + int cnt; + TPkt pkt; + + while ((cnt = tmsg_get((byte *)&pkt)) != 0) { + HandleAllPackets(myplr, (byte *)&pkt, cnt); + } +} + +void SendPlayerInfo(int pnum, _cmd_id cmd) +{ + PkPlayerStruct pkplr; + + PackPlayer(&pkplr, plr[myplr], true); + dthread_send_delta(pnum, cmd, (byte *)&pkplr, sizeof(pkplr)); +} + +dungeon_type InitLevelType(int l) +{ + if (l == 0) + return DTYPE_TOWN; + if (l >= 1 && l <= 4) + return DTYPE_CATHEDRAL; + if (l >= 5 && l <= 8) + return DTYPE_CATACOMBS; + if (l >= 9 && l <= 12) + return DTYPE_CAVES; + if (l >= 13 && l <= 16) + return DTYPE_HELL; + if (l >= 21 && l <= 24) + return DTYPE_CATHEDRAL; // Crypt + if (l >= 17 && l <= 20) + return DTYPE_CAVES; // Hive + + return DTYPE_CATHEDRAL; +} + +void SetupLocalPositions() +{ + if (!leveldebug || gbIsMultiplayer) { + currlevel = 0; + leveltype = DTYPE_TOWN; + setlevel = false; + } + + int x = 75; + int y = 68; +#ifdef _DEBUG + if (debug_mode_key_inverted_v) { + x = 49; + y = 23; + } +#endif + + x += plrxoff[myplr]; + y += plryoff[myplr]; + plr[myplr].position.tile = { x, y }; + plr[myplr].position.future = { x, y }; + plr[myplr].plrlevel = currlevel; + plr[myplr]._pLvlChanging = true; + plr[myplr].pLvlLoad = 0; + plr[myplr]._pmode = PM_NEWLVL; + plr[myplr].destAction = ACTION_NONE; +} + +void HandleEvents(_SNETEVENT *pEvt) +{ + DWORD LeftReason; + + switch (pEvt->eventid) { + case EVENT_TYPE_PLAYER_CREATE_GAME: { + auto *gameData = (GameData *)pEvt->data; + if (gameData->size != sizeof(GameData)) + app_fatal("Invalid size of game data: %i", gameData->size); + sgGameInitInfo = *gameData; + sgbPlayerTurnBitTbl[pEvt->playerid] = true; + break; + } + case EVENT_TYPE_PLAYER_LEAVE_GAME: + sgbPlayerLeftGameTbl[pEvt->playerid] = true; + sgbPlayerTurnBitTbl[pEvt->playerid] = false; + + LeftReason = 0; + if (pEvt->data != nullptr && pEvt->databytes >= sizeof(DWORD)) + LeftReason = *(DWORD *)pEvt->data; + sgdwPlayerLeftReasonTbl[pEvt->playerid] = LeftReason; + if (LeftReason == LEAVE_ENDING) + gbSomebodyWonGameKludge = true; + + sgbSendDeltaTbl[pEvt->playerid] = false; + dthread_remove_player(pEvt->playerid); + + if (gbDeltaSender == pEvt->playerid) + gbDeltaSender = MAX_PLRS; + break; + case EVENT_TYPE_PLAYER_MESSAGE: + ErrorPlrMsg((char *)pEvt->data); + break; + } +} + +void EventHandler(bool add) +{ + for (auto eventType : EventTypes) { + if (add) { + if (!SNetRegisterEventHandler(eventType, HandleEvents)) { + app_fatal("SNetRegisterEventHandler:\n%s", SDL_GetError()); + } + } else { + SNetUnregisterEventHandler(eventType); + } + } +} + +bool InitSingle(GameData *gameData) +{ + if (!SNetInitializeProvider(SELCONN_LOOPBACK, gameData)) { + SErrGetLastError(); + return false; + } + + int unused = 0; + if (!SNetCreateGame("local", "local", (char *)&sgGameInitInfo, sizeof(sgGameInitInfo), &unused)) { + app_fatal("SNetCreateGame1:\n%s", SDL_GetError()); + } + + myplr = 0; + gbIsMultiplayer = false; + + return true; +} + +bool InitMulti(GameData *gameData) +{ + int playerId; + + while (true) { + if (gbSelectProvider && !UiSelectProvider(gameData)) { + return false; + } + + EventHandler(true); + if (UiSelectGame(gameData, &playerId)) + break; + + gbSelectProvider = true; + } + + if ((DWORD)playerId >= MAX_PLRS) { + return false; + } + myplr = playerId; + gbIsMultiplayer = true; + + pfile_read_player_from_save(gszHero, myplr); + + return true; +} + +} // namespace + +void multi_msg_add(byte *pbMsg, BYTE bLen) +{ + if (pbMsg != nullptr && bLen != 0) { + tmsg_add(pbMsg, bLen); + } +} + +void NetSendLoPri(int playerId, byte *pbMsg, BYTE bLen) +{ + if (pbMsg != nullptr && bLen != 0) { + CopyPacket(&sgLoPriBuf, pbMsg, bLen); + SendPacket(playerId, pbMsg, bLen); + } +} + +void NetSendHiPri(int playerId, byte *pbMsg, BYTE bLen) +{ + if (pbMsg != nullptr && bLen != 0) { + CopyPacket(&sgHiPriBuf, pbMsg, bLen); + SendPacket(playerId, pbMsg, bLen); + } + if (!gbShouldValidatePackage) { + gbShouldValidatePackage = true; + TPkt pkt; + NetReceivePlayerData(&pkt); + size_t size = gdwNormalMsgSize - sizeof(TPktHdr); + byte *hipri_body = ReceivePacket(&sgHiPriBuf, pkt.body, &size); + byte *lowpri_body = ReceivePacket(&sgLoPriBuf, hipri_body, &size); + size = sync_all_monsters(lowpri_body, size); + size_t len = gdwNormalMsgSize - size; + pkt.hdr.wLen = len; + if (!SNetSendMessage(-2, &pkt.hdr, len)) + nthread_terminate_game("SNetSendMessage"); + } +} + +void multi_send_msg_packet(uint32_t pmask, byte *src, BYTE len) +{ + TPkt pkt; + NetReceivePlayerData(&pkt); + size_t t = len + sizeof(pkt.hdr); + pkt.hdr.wLen = t; + memcpy(pkt.body, src, len); + size_t p = 0; + for (size_t v = 1; p < MAX_PLRS; p++, v <<= 1) { + if ((v & pmask) != 0) { + if (!SNetSendMessage(p, &pkt.hdr, t) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) { + nthread_terminate_game("SNetSendMessage"); + return; + } + } + } +} + +void multi_msg_countdown() +{ + for (int i = 0; i < MAX_PLRS; i++) { + if ((player_state[i] & PS_TURN_ARRIVED) != 0) { + if (gdwMsgLenTbl[i] == 4) + ParseTurn(i, *(DWORD *)glpMsgTbl[i]); + } + } +} + +void multi_player_left(int pnum, int reason) +{ + sgbPlayerLeftGameTbl[pnum] = true; + sgdwPlayerLeftReasonTbl[pnum] = reason; + ClearPlayerLeftState(); +} + +void multi_net_ping() +{ + sgbTimeout = true; + sglTimeoutStart = SDL_GetTicks(); +} + /** * @return Always true for singleplayer */ bool multi_handle_delta() { - int i; - bool received; - if (gbGameDestroyed) { gbRunGame = false; return false; } - for (i = 0; i < MAX_PLRS; i++) { + for (int i = 0; i < MAX_PLRS; i++) { if (sgbSendDeltaTbl[i]) { sgbSendDeltaTbl[i] = false; DeltaExportData(i); @@ -391,8 +556,9 @@ bool multi_handle_delta() } sgbSentThisCycle = nthread_send_and_recv_turn(sgbSentThisCycle, 1); + bool received; if (!nthread_recv_turns(&received)) { - multi_begin_timeout(); + BeginTimeout(); return false; } @@ -407,46 +573,22 @@ bool multi_handle_delta() NetSendHiPri(myplr, nullptr, 0); } } - multi_mon_seeds(); + MonsterSeeds(); return true; } -static void multi_handle_all_packets(int pnum, byte *pData, int nSize) -{ - int nLen; - - while (nSize != 0) { - nLen = ParseCmd(pnum, (TCmd *)pData); - if (nLen == 0) { - break; - } - pData += nLen; - nSize -= nLen; - } -} - -static void multi_process_tmsgs() -{ - int cnt; - TPkt pkt; - - while ((cnt = tmsg_get((byte *)&pkt)) != 0) { - multi_handle_all_packets(myplr, (byte *)&pkt, cnt); - } -} - void multi_process_network_packets() { - multi_clear_left_tbl(); - multi_process_tmsgs(); + ClearPlayerLeftState(); + ProcessTmsgs(); int dwID = -1; TPktHdr *pkt; uint32_t dwMsgSize = 0; while (SNetReceiveMessage(&dwID, (void **)&pkt, &dwMsgSize)) { dwRecCount++; - multi_clear_left_tbl(); + ClearPlayerLeftState(); if (dwMsgSize < sizeof(TPktHdr)) continue; if (dwID < 0 || dwID >= MAX_PLRS) @@ -488,7 +630,7 @@ void multi_process_network_packets() } } } - multi_handle_all_packets(dwID, (byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr)); + HandleAllPackets(dwID, (byte *)(pkt + 1), dwMsgSize - sizeof(TPktHdr)); } if (SErrGetLastError() != STORM_ERROR_NO_MESSAGES_WAITING) nthread_terminate_game("SNetReceiveMsg"); @@ -532,135 +674,13 @@ void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen) nthread_terminate_game("SNetSendMessage2"); return; } -#if 0 - if((DWORD)pnum >= MAX_PLRS) { - if(myplr != 0) { - debug_plr_tbl[0]++; - } - if(myplr != 1) { - debug_plr_tbl[1]++; - } - if(myplr != 2) { - debug_plr_tbl[2]++; - } - if(myplr != 3) { - debug_plr_tbl[3]++; - } - } else { - debug_plr_tbl[pnum]++; - } -#endif + pbSrc += p->wBytes; dwLen -= p->wBytes; dwOffset += p->wBytes; } } -static void multi_send_pinfo(int pnum, _cmd_id cmd) -{ - PkPlayerStruct pkplr; - - PackPlayer(&pkplr, plr[myplr], true); - dthread_send_delta(pnum, cmd, (byte *)&pkplr, sizeof(pkplr)); -} - -static dungeon_type InitLevelType(int l) -{ - if (l == 0) - return DTYPE_TOWN; - if (l >= 1 && l <= 4) - return DTYPE_CATHEDRAL; - if (l >= 5 && l <= 8) - return DTYPE_CATACOMBS; - if (l >= 9 && l <= 12) - return DTYPE_CAVES; - if (l >= 13 && l <= 16) - return DTYPE_HELL; - if (l >= 21 && l <= 24) - return DTYPE_CATHEDRAL; // Crypt - if (l >= 17 && l <= 20) - return DTYPE_CAVES; // Hive - - return DTYPE_CATHEDRAL; -} - -static void SetupLocalCoords() -{ - if (!leveldebug || gbIsMultiplayer) { - currlevel = 0; - leveltype = DTYPE_TOWN; - setlevel = false; - } - - int x = 75; - int y = 68; -#ifdef _DEBUG - if (debug_mode_key_inverted_v) { - x = 49; - y = 23; - } -#endif - - x += plrxoff[myplr]; - y += plryoff[myplr]; - plr[myplr].position.tile = { x, y }; - plr[myplr].position.future = { x, y }; - plr[myplr].plrlevel = currlevel; - plr[myplr]._pLvlChanging = true; - plr[myplr].pLvlLoad = 0; - plr[myplr]._pmode = PM_NEWLVL; - plr[myplr].destAction = ACTION_NONE; -} - -static void multi_handle_events(_SNETEVENT *pEvt) -{ - DWORD LeftReason; - - switch (pEvt->eventid) { - case EVENT_TYPE_PLAYER_CREATE_GAME: { - auto *gameData = (GameData *)pEvt->data; - if (gameData->size != sizeof(GameData)) - app_fatal("Invalid size of game data: %i", gameData->size); - sgGameInitInfo = *gameData; - sgbPlayerTurnBitTbl[pEvt->playerid] = true; - break; - } - case EVENT_TYPE_PLAYER_LEAVE_GAME: - sgbPlayerLeftGameTbl[pEvt->playerid] = true; - sgbPlayerTurnBitTbl[pEvt->playerid] = false; - - LeftReason = 0; - if (pEvt->data != nullptr && pEvt->databytes >= sizeof(DWORD)) - LeftReason = *(DWORD *)pEvt->data; - sgdwPlayerLeftReasonTbl[pEvt->playerid] = LeftReason; - if (LeftReason == LEAVE_ENDING) - gbSomebodyWonGameKludge = true; - - sgbSendDeltaTbl[pEvt->playerid] = false; - dthread_remove_player(pEvt->playerid); - - if (gbDeltaSender == pEvt->playerid) - gbDeltaSender = MAX_PLRS; - break; - case EVENT_TYPE_PLAYER_MESSAGE: - ErrorPlrMsg((char *)pEvt->data); - break; - } -} - -static void multi_event_handler(bool add) -{ - for (auto eventType : EventTypes) { - if (add) { - if (!SNetRegisterEventHandler(eventType, multi_handle_events)) { - app_fatal("SNetRegisterEventHandler:\n%s", SDL_GetError()); - } - } else { - SNetUnregisterEventHandler(eventType); - } - } -} - void NetClose() { if (!sgbNetInited) { @@ -671,7 +691,7 @@ void NetClose() nthread_cleanup(); dthread_cleanup(); tmsg_cleanup(); - multi_event_handler(false); + EventHandler(false); SNetLeaveGame(3); if (gbIsMultiplayer) SDL_Delay(2000); @@ -703,18 +723,18 @@ bool NetInit(bool bSinglePlayer) memset(sgwPackPlrOffsetTbl, 0, sizeof(sgwPackPlrOffsetTbl)); SNetSetBasePlayer(0); if (bSinglePlayer) { - if (!multi_init_single(&sgGameInitInfo)) + if (!InitSingle(&sgGameInitInfo)) return false; } else { - if (!multi_init_multi(&sgGameInitInfo)) + if (!InitMulti(&sgGameInitInfo)) return false; } sgbNetInited = true; sgbTimeout = false; delta_init(); InitPlrMsg(); - buffer_init(&sgHiPriBuf); - buffer_init(&sgLoPriBuf); + BufferInit(&sgHiPriBuf); + BufferInit(&sgLoPriBuf); gbShouldValidatePackage = false; sync_init(); nthread_start(sgbPlayerTurnBitTbl[myplr]); @@ -725,8 +745,8 @@ bool NetInit(bool bSinglePlayer) gbDeltaSender = myplr; gbSomebodyWonGameKludge = false; nthread_send_and_recv_turn(0, 0); - SetupLocalCoords(); - multi_send_pinfo(-2, CMD_SEND_PLRINFO); + SetupLocalPositions(); + SendPlayerInfo(-2, CMD_SEND_PLRINFO); ResetPlayerGFX(plr[myplr]); plr[myplr].plractive = true; @@ -752,53 +772,6 @@ bool NetInit(bool bSinglePlayer) return true; } -bool multi_init_single(GameData *gameData) -{ - int unused; - - if (!SNetInitializeProvider(SELCONN_LOOPBACK, gameData)) { - SErrGetLastError(); - return false; - } - - unused = 0; - if (!SNetCreateGame("local", "local", (char *)&sgGameInitInfo, sizeof(sgGameInitInfo), &unused)) { - app_fatal("SNetCreateGame1:\n%s", SDL_GetError()); - } - - myplr = 0; - gbIsMultiplayer = false; - - return true; -} - -bool multi_init_multi(GameData *gameData) -{ - int playerId; - - while (true) { - if (gbSelectProvider && !UiSelectProvider(gameData)) { - return false; - } - - multi_event_handler(true); - if (UiSelectGame(gameData, &playerId)) - break; - - gbSelectProvider = true; - } - - if ((DWORD)playerId >= MAX_PLRS) { - return false; - } - myplr = playerId; - gbIsMultiplayer = true; - - pfile_read_player_from_save(gszHero, myplr); - - return true; -} - void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) { const char *szEvent; @@ -816,7 +789,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) } } if (!recv && sgwPackPlrOffsetTbl[pnum] == 0) { - multi_send_pinfo(pnum, CMD_ACK_PLRINFO); + SendPlayerInfo(pnum, CMD_ACK_PLRINFO); } memcpy((char *)&netplr[pnum] + p->wOffset, &p[1], p->wBytes); /* todo: cast? */ @@ -826,7 +799,7 @@ void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv) } sgwPackPlrOffsetTbl[pnum] = 0; - multi_player_left_msg(pnum, false); + PlayerLeftMsg(pnum, false); UnPackPlayer(&netplr[pnum], pnum, true); if (!recv) { diff --git a/Source/multi.h b/Source/multi.h index 8285c004b..45780e906 100644 --- a/Source/multi.h +++ b/Source/multi.h @@ -60,8 +60,6 @@ void multi_process_network_packets(); void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen); void NetClose(); bool NetInit(bool bSinglePlayer); -bool multi_init_single(GameData *gameData); -bool multi_init_multi(GameData *gameData); void recv_plrinfo(int pnum, TCmdPlrInfoHdr *p, bool recv); } // namespace devilution diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 20aa35ad8..efe53ba4e 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -27,8 +27,13 @@ namespace devilution { #define PASSWORD_SINGLE "xrgyrkj1" #define PASSWORD_MULTI "szqnlsk1" +bool gbValidSaveFile; + namespace { +/** List of character names for the character selection screen. */ +char hero_names[MAX_CHARACTERS][PLR_NAME_LEN]; + std::string GetSavePath(uint32_t save_num) { std::string path = paths::PrefPath(); @@ -89,7 +94,7 @@ bool GetTempSaveNames(uint8_t dwIndex, char *szTemp) return true; } -void pfile_rename_temp_to_perm() +void RenameTempToPerm() { char szTemp[MAX_PATH]; char szPerm[MAX_PATH]; @@ -108,20 +113,7 @@ void pfile_rename_temp_to_perm() assert(!GetPermSaveNames(dwIndex, szPerm)); } -} // namespace - -/** List of character names for the character selection screen. */ -static char hero_names[MAX_CHARACTERS][PLR_NAME_LEN]; -bool gbValidSaveFile; - -const char *pfile_get_password() -{ - if (gbIsSpawn) - return gbIsMultiplayer ? PASSWORD_SPAWN_MULTI : PASSWORD_SPAWN_SINGLE; - return gbIsMultiplayer ? PASSWORD_MULTI : PASSWORD_SINGLE; -} - -static uint32_t pfile_get_save_num_from_name(const char *name) +uint32_t GetSaveNumberFromName(const char *name) { uint32_t i; @@ -133,7 +125,7 @@ static uint32_t pfile_get_save_num_from_name(const char *name) return i; } -static std::unique_ptr pfile_read_archive(HANDLE archive, const char *pszName, size_t *pdwLen = nullptr) +std::unique_ptr ReadArchive(HANDLE archive, const char *pszName, size_t *pdwLen = nullptr) { HANDLE file; @@ -159,11 +151,11 @@ static std::unique_ptr pfile_read_archive(HANDLE archive, const char *ps return buf; } -static bool pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) +bool ReadHero(HANDLE archive, PkPlayerStruct *pPack) { size_t read; - auto buf = pfile_read_archive(archive, "hero", &read); + auto buf = ReadArchive(archive, "hero", &read); if (buf == nullptr) return false; @@ -176,7 +168,7 @@ static bool pfile_read_hero(HANDLE archive, PkPlayerStruct *pPack) return ret; } -static void pfile_encode_hero(const PkPlayerStruct *pack) +void EncodeHero(const PkPlayerStruct *pack) { size_t packedLen = codec_get_encoded_len(sizeof(*pack)); std::unique_ptr packed { new byte[packedLen] }; @@ -186,12 +178,12 @@ static void pfile_encode_hero(const PkPlayerStruct *pack) mpqapi_write_file("hero", packed.get(), packedLen); } -static bool pfile_open_archive(uint32_t save_num) +bool OpenArchive(uint32_t save_num) { return OpenMPQ(GetSavePath(save_num).c_str()); } -static HANDLE pfile_open_save_archive(uint32_t save_num) +HANDLE OpenSaveArchive(uint32_t save_num) { HANDLE archive; @@ -200,7 +192,7 @@ static HANDLE pfile_open_save_archive(uint32_t save_num) return nullptr; } -static void pfile_SFileCloseArchive(HANDLE *hsArchive) +void CloseArchive(HANDLE *hsArchive) { if (*hsArchive == nullptr) return; @@ -209,11 +201,75 @@ static void pfile_SFileCloseArchive(HANDLE *hsArchive) *hsArchive = nullptr; } +void Game2UiPlayer(const PlayerStruct &player, _uiheroinfo *heroinfo, bool bHasSaveFile) +{ + memset(heroinfo, 0, sizeof(*heroinfo)); + strncpy(heroinfo->name, player._pName, sizeof(heroinfo->name) - 1); + heroinfo->name[sizeof(heroinfo->name) - 1] = '\0'; + heroinfo->level = player._pLevel; + heroinfo->heroclass = player._pClass; + heroinfo->strength = player._pStrength; + heroinfo->magic = player._pMagic; + heroinfo->dexterity = player._pDexterity; + heroinfo->vitality = player._pVitality; + heroinfo->hassaved = bHasSaveFile; + heroinfo->herorank = player.pDiabloKillLevel; + heroinfo->spawned = gbIsSpawn; +} + +bool GetFileName(uint8_t lvl, char *dst) +{ + const char *fmt; + + if (gbIsMultiplayer) { + if (lvl != 0) + return false; + fmt = "hero"; + } else { + if (lvl < giNumberOfLevels) + fmt = "perml%02d"; + else if (lvl < giNumberOfLevels * 2) { + lvl -= giNumberOfLevels; + fmt = "perms%02d"; + } else if (lvl == giNumberOfLevels * 2) + fmt = "game"; + else if (lvl == giNumberOfLevels * 2 + 1) + fmt = "hero"; + else + return false; + } + sprintf(dst, fmt, lvl); + return true; +} + +bool ArchiveContainsGame(HANDLE hsArchive) +{ + if (gbIsMultiplayer) + return false; + + auto gameData = ReadArchive(hsArchive, "game"); + if (gameData == nullptr) + return false; + + uint32_t hdr = LoadLE32(gameData.get()); + + return IsHeaderValid(hdr); +} + +} // namespace + +const char *pfile_get_password() +{ + if (gbIsSpawn) + return gbIsMultiplayer ? PASSWORD_SPAWN_MULTI : PASSWORD_SPAWN_SINGLE; + return gbIsMultiplayer ? PASSWORD_MULTI : PASSWORD_SINGLE; +} + PFileScopedArchiveWriter::PFileScopedArchiveWriter(bool clear_tables) - : save_num_(pfile_get_save_num_from_name(plr[myplr]._pName)) + : save_num_(GetSaveNumberFromName(plr[myplr]._pName)) , clear_tables_(clear_tables) { - if (!pfile_open_archive(save_num_)) + if (!OpenArchive(save_num_)) app_fatal("%s", _("Failed to open player archive for writing.")); } @@ -227,79 +283,49 @@ void pfile_write_hero(bool write_game_data, bool clear_tables) PFileScopedArchiveWriter scoped_writer(clear_tables); if (write_game_data) { SaveGameData(); - pfile_rename_temp_to_perm(); + RenameTempToPerm(); } PkPlayerStruct pkplr; PackPlayer(&pkplr, plr[myplr], !gbIsMultiplayer); - pfile_encode_hero(&pkplr); + EncodeHero(&pkplr); if (!gbVanilla) { SaveHotkeys(); SaveHeroItems(plr[myplr]); } } -static void game_2_ui_player(const PlayerStruct &player, _uiheroinfo *heroinfo, bool bHasSaveFile) -{ - memset(heroinfo, 0, sizeof(*heroinfo)); - strncpy(heroinfo->name, player._pName, sizeof(heroinfo->name) - 1); - heroinfo->name[sizeof(heroinfo->name) - 1] = '\0'; - heroinfo->level = player._pLevel; - heroinfo->heroclass = player._pClass; - heroinfo->strength = player._pStrength; - heroinfo->magic = player._pMagic; - heroinfo->dexterity = player._pDexterity; - heroinfo->vitality = player._pVitality; - heroinfo->hassaved = bHasSaveFile; - heroinfo->herorank = player.pDiabloKillLevel; - heroinfo->spawned = gbIsSpawn; -} - bool pfile_ui_set_hero_infos(bool (*ui_add_hero_info)(_uiheroinfo *)) { memset(hero_names, 0, sizeof(hero_names)); for (uint32_t i = 0; i < MAX_CHARACTERS; i++) { - HANDLE archive = pfile_open_save_archive(i); + HANDLE archive = OpenSaveArchive(i); if (archive != nullptr) { PkPlayerStruct pkplr; - if (pfile_read_hero(archive, &pkplr)) { + if (ReadHero(archive, &pkplr)) { _uiheroinfo uihero; strcpy(hero_names[i], pkplr.pName); - bool hasSaveGame = pfile_archive_contains_game(archive); + bool hasSaveGame = ArchiveContainsGame(archive); if (hasSaveGame) pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0; UnPackPlayer(&pkplr, 0, false); - pfile_SFileCloseArchive(&archive); + CloseArchive(&archive); LoadHeroItems(plr[0]); RemoveEmptyInventory(plr[0]); CalcPlrInv(0, false); - game_2_ui_player(plr[0], &uihero, hasSaveGame); + Game2UiPlayer(plr[0], &uihero, hasSaveGame); ui_add_hero_info(&uihero); } - pfile_SFileCloseArchive(&archive); + CloseArchive(&archive); } } return true; } -bool pfile_archive_contains_game(HANDLE hsArchive) -{ - if (gbIsMultiplayer) - return false; - - auto gameData = pfile_read_archive(hsArchive, "game"); - if (gameData == nullptr) - return false; - - uint32_t hdr = LoadLE32(gameData.get()); - - return IsHeaderValid(hdr); -} - void pfile_ui_set_class_stats(unsigned int player_class_nr, _uidefaultstats *class_stats) { class_stats->strength = StrengthTbl[player_class_nr]; @@ -312,7 +338,7 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) { PkPlayerStruct pkplr; - uint32_t save_num = pfile_get_save_num_from_name(heroinfo->name); + uint32_t save_num = GetSaveNumberFromName(heroinfo->name); if (save_num >= MAX_CHARACTERS) { for (save_num = 0; save_num < MAX_CHARACTERS; save_num++) { if (hero_names[save_num][0] == '\0') @@ -321,9 +347,9 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) if (save_num >= MAX_CHARACTERS) return false; } - if (!pfile_open_archive(save_num)) + if (!OpenArchive(save_num)) return false; - mpqapi_remove_hash_entries(pfile_get_file_name); + mpqapi_remove_hash_entries(GetFileName); strncpy(hero_names[save_num], heroinfo->name, PLR_NAME_LEN); hero_names[save_num][PLR_NAME_LEN - 1] = '\0'; @@ -332,8 +358,8 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) strncpy(player._pName, heroinfo->name, PLR_NAME_LEN); player._pName[PLR_NAME_LEN - 1] = '\0'; PackPlayer(&pkplr, player, true); - pfile_encode_hero(&pkplr); - game_2_ui_player(player, heroinfo, false); + EncodeHero(&pkplr); + Game2UiPlayer(player, heroinfo, false); if (!gbVanilla) { SaveHotkeys(); SaveHeroItems(player); @@ -343,34 +369,9 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo) return true; } -bool pfile_get_file_name(uint8_t lvl, char *dst) -{ - const char *fmt; - - if (gbIsMultiplayer) { - if (lvl != 0) - return false; - fmt = "hero"; - } else { - if (lvl < giNumberOfLevels) - fmt = "perml%02d"; - else if (lvl < giNumberOfLevels * 2) { - lvl -= giNumberOfLevels; - fmt = "perms%02d"; - } else if (lvl == giNumberOfLevels * 2) - fmt = "game"; - else if (lvl == giNumberOfLevels * 2 + 1) - fmt = "hero"; - else - return false; - } - sprintf(dst, fmt, lvl); - return true; -} - bool pfile_delete_save(_uiheroinfo *hero_info) { - uint32_t save_num = pfile_get_save_num_from_name(hero_info->name); + uint32_t save_num = GetSaveNumberFromName(hero_info->name); if (save_num < MAX_CHARACTERS) { hero_names[save_num][0] = '\0'; RemoveFile(GetSavePath(save_num).c_str()); @@ -383,18 +384,18 @@ void pfile_read_player_from_save(char name[16], int playerId) HANDLE archive; PkPlayerStruct pkplr; - uint32_t save_num = pfile_get_save_num_from_name(name); - archive = pfile_open_save_archive(save_num); + uint32_t save_num = GetSaveNumberFromName(name); + archive = OpenSaveArchive(save_num); if (archive == nullptr) app_fatal("%s", _("Unable to open archive")); - if (!pfile_read_hero(archive, &pkplr)) + if (!ReadHero(archive, &pkplr)) app_fatal("%s", _("Unable to load character")); - gbValidSaveFile = pfile_archive_contains_game(archive); + gbValidSaveFile = ArchiveContainsGame(archive); if (gbValidSaveFile) pkplr.bIsHellfire = gbIsHellfireSaveGame ? 1 : 0; - pfile_SFileCloseArchive(&archive); + CloseArchive(&archive); UnPackPlayer(&pkplr, playerId, false); @@ -409,8 +410,8 @@ bool LevelFileExists() GetPermLevelNames(szName); - uint32_t save_num = pfile_get_save_num_from_name(plr[myplr]._pName); - if (!pfile_open_archive(save_num)) + uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); + if (!OpenArchive(save_num)) app_fatal("%s", _("Unable to read to save file archive")); bool has_file = mpqapi_has_file(szName); @@ -428,9 +429,9 @@ void GetTempLevelNames(char *szTemp) void GetPermLevelNames(char *szPerm) { - uint32_t save_num = pfile_get_save_num_from_name(plr[myplr]._pName); + uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); GetTempLevelNames(szPerm); - if (!pfile_open_archive(save_num)) + if (!OpenArchive(save_num)) app_fatal("%s", _("Unable to read to save file archive")); bool has_file = mpqapi_has_file(szPerm); @@ -448,8 +449,8 @@ void pfile_remove_temp_files() if (gbIsMultiplayer) return; - uint32_t save_num = pfile_get_save_num_from_name(plr[myplr]._pName); - if (!pfile_open_archive(save_num)) + uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); + if (!OpenArchive(save_num)) app_fatal("%s", _("Unable to write to save file archive")); mpqapi_remove_hash_entries(GetTempSaveNames); mpqapi_flush_and_close(true); @@ -459,13 +460,13 @@ std::unique_ptr pfile_read(const char *pszName, size_t *pdwLen) { HANDLE archive; - uint32_t save_num = pfile_get_save_num_from_name(plr[myplr]._pName); - archive = pfile_open_save_archive(save_num); + uint32_t save_num = GetSaveNumberFromName(plr[myplr]._pName); + archive = OpenSaveArchive(save_num); if (archive == nullptr) return nullptr; - auto buf = pfile_read_archive(archive, pszName, pdwLen); - pfile_SFileCloseArchive(&archive); + auto buf = ReadArchive(archive, pszName, pdwLen); + CloseArchive(&archive); if (buf == nullptr) return nullptr; diff --git a/Source/pfile.h b/Source/pfile.h index 56fdc1365..bd7225829 100644 --- a/Source/pfile.h +++ b/Source/pfile.h @@ -30,10 +30,8 @@ private: const char *pfile_get_password(); void pfile_write_hero(bool write_game_data = false, bool clear_tables = !gbIsMultiplayer); bool pfile_ui_set_hero_infos(bool (*ui_add_hero_info)(_uiheroinfo *)); -bool pfile_archive_contains_game(HANDLE hsArchive); void pfile_ui_set_class_stats(unsigned int player_class_nr, _uidefaultstats *class_stats); bool pfile_ui_save_create(_uiheroinfo *heroinfo); -bool pfile_get_file_name(uint8_t lvl, char *dst); bool pfile_delete_save(_uiheroinfo *hero_info); void pfile_read_player_from_save(char name[16], int playerId); bool LevelFileExists(); diff --git a/Source/stores.cpp b/Source/stores.cpp index 25eb6e651..803ae034a 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -212,7 +212,7 @@ void StoreAutoPlace() AutoPlaceItemInInventory(myPlayer, myPlayer.HoldItem, true); } -void S_StartSmith() +void StartSmith() { stextsize = false; stextscrl = false; @@ -229,7 +229,7 @@ void S_StartSmith() storenumh = 20; } -void S_ScrollSBuy(int idx) +void ScrollSmithBuy(int idx) { ClearSText(5, 21); stextup = 5; @@ -255,7 +255,7 @@ void S_ScrollSBuy(int idx) stextsel = stextdown; } -void S_StartSBuy() +void StartSmithBuy() { stextsize = true; stextscrl = true; @@ -267,7 +267,7 @@ void S_StartSBuy() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSBuy(stextsval); + ScrollSmithBuy(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, false); OffsetSTextY(22, 6); @@ -281,7 +281,7 @@ void S_StartSBuy() stextsmax = 0; } -void S_ScrollSPBuy(int boughtitems) +void ScrollSmithPremiumBuy(int boughtitems) { ClearSText(5, 21); stextup = 5; @@ -308,7 +308,7 @@ void S_ScrollSPBuy(int boughtitems) stextsel = stextdown; } -bool S_StartSPBuy() +bool StartSmithPremiumBuy() { storenumh = 0; for (const auto &item : premiumitems) { @@ -338,7 +338,7 @@ bool S_StartSPBuy() if (stextsmax < 0) stextsmax = 0; - S_ScrollSPBuy(stextsval); + ScrollSmithPremiumBuy(stextsval); return true; } @@ -373,7 +373,7 @@ bool SmithSellOk(int i) return true; } -void S_ScrollSSell(int idx) +void ScrollSmithSell(int idx) { int l; @@ -405,7 +405,7 @@ void S_ScrollSSell(int idx) stextsmax = 0; } -void S_StartSSell() +void StartSmithSell() { stextsize = true; bool sellok = false; @@ -475,7 +475,7 @@ void S_StartSSell() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); } @@ -496,7 +496,7 @@ bool SmithRepairOk(int i) return true; } -void S_StartSRepair() +void StartSmithRepair() { stextsize = true; bool repairok = false; @@ -565,7 +565,7 @@ void S_StartSRepair() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); } @@ -585,7 +585,7 @@ void FillManaPlayer() drawmanaflag = true; } -void S_StartWitch() +void StartWitch() { FillManaPlayer(); stextsize = false; @@ -601,7 +601,7 @@ void S_StartWitch() storenumh = 20; } -void S_ScrollWBuy(int idx) +void ScrollWitchBuy(int idx) { ClearSText(5, 21); stextup = 5; @@ -627,7 +627,7 @@ void S_ScrollWBuy(int idx) stextsel = stextdown; } -void S_StartWBuy() +void StartWitchBuy() { int i; @@ -642,7 +642,7 @@ void S_StartWBuy() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollWBuy(stextsval); + ScrollWitchBuy(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, false); OffsetSTextY(22, 6); @@ -681,7 +681,7 @@ bool WitchSellOk(int i) return rv; } -void S_StartWSell() +void StartWitchSell() { stextsize = true; bool sellok = false; @@ -751,7 +751,7 @@ void S_StartWSell() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); } @@ -781,7 +781,7 @@ void AddStoreHoldRecharge(ItemStruct itm, int i) storenumh++; } -void S_StartWRecharge() +void StartWitchRecharge() { stextsize = true; bool rechargeok = false; @@ -832,12 +832,12 @@ void S_StartWRecharge() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); } -void S_StartNoMoney() +void StoreNoMoney() { StartStore(stextshold); stextscrl = false; @@ -846,7 +846,7 @@ void S_StartNoMoney() AddSText(0, 14, _("You do not have enough gold"), UIS_SILVER | UIS_CENTER, true); } -void S_StartNoRoom() +void StoreNoRoom() { StartStore(stextshold); stextscrl = false; @@ -854,7 +854,7 @@ void S_StartNoRoom() AddSText(0, 14, _("You do not have enough room in inventory"), UIS_SILVER | UIS_CENTER, true); } -void S_StartConfirm() +void StoreConfirm() { StartStore(stextshold); stextscrl = false; @@ -917,7 +917,7 @@ void S_StartConfirm() AddSText(0, 20, _("No"), UIS_SILVER | UIS_CENTER, true); } -void S_StartBoy() +void StartBoy() { stextsize = false; stextscrl = false; @@ -936,7 +936,7 @@ void S_StartBoy() } } -void S_StartBBoy() +void SStartBoyBuy() { stextsize = true; stextscrl = false; @@ -975,7 +975,7 @@ void HealPlayer() drawhpflag = true; } -void S_StartHealer() +void StartHealer() { HealPlayer(); stextsize = false; @@ -990,7 +990,7 @@ void S_StartHealer() storenumh = 20; } -void S_ScrollHBuy(int idx) +void ScrollHealerBuy(int idx) { int l; @@ -1012,10 +1012,8 @@ void S_ScrollHBuy(int idx) stextsel = stextdown; } -void S_StartHBuy() +void StartHealerBuy() { - int i; - stextsize = true; stextscrl = true; stextsval = 0; @@ -1026,12 +1024,12 @@ void S_StartHBuy() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollHBuy(stextsval); + ScrollHealerBuy(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, false); OffsetSTextY(22, 6); storenumh = 0; - for (i = 0; !healitem[i].isEmpty(); i++) { + for (int i = 0; !healitem[i].isEmpty(); i++) { storenumh++; } stextsmax = storenumh - 4; @@ -1039,7 +1037,7 @@ void S_StartHBuy() stextsmax = 0; } -void S_StartStory() +void StartStoryteller() { stextsize = false; stextscrl = false; @@ -1071,7 +1069,7 @@ void AddStoreHoldId(ItemStruct itm, int i) storenumh++; } -void S_StartSIdentify() +void StartStorytellerIdentify() { bool idok = false; stextsize = true; @@ -1159,12 +1157,12 @@ void S_StartSIdentify() AddSText(0, 1, tempstr, UIS_GOLD | UIS_CENTER, false); AddSLine(3); AddSLine(21); - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); OffsetSTextY(22, 6); } -void S_StartIdShow() +void StartStorytellerIdentifyShow() { StartStore(stextshold); stextscrl = false; @@ -1180,7 +1178,7 @@ void S_StartIdShow() AddSText(0, 18, _("Done"), UIS_SILVER | UIS_CENTER, true); } -void S_StartTalk() +void StartTalk() { int la; @@ -1225,7 +1223,7 @@ void S_StartTalk() AddSText(0, 22, _("Back"), UIS_SILVER | UIS_CENTER, true); } -void S_StartTavern() +void StartTavern() { stextsize = false; stextscrl = false; @@ -1238,7 +1236,7 @@ void S_StartTavern() storenumh = 20; } -void S_StartBarMaid() +void StartBarmaid() { stextsize = false; stextscrl = false; @@ -1250,7 +1248,7 @@ void S_StartBarMaid() storenumh = 20; } -void S_StartDrunk() +void StartDrunk() { stextsize = false; stextscrl = false; @@ -1262,7 +1260,7 @@ void S_StartDrunk() storenumh = 20; } -void S_SmithEnter() +void SmithEnter() { switch (stextsel) { case 10: @@ -1314,7 +1312,7 @@ void SmithBuyItem() CalcPlrInv(myplr, true); } -void S_SBuyEnter() +void SmitBuyEnter() { if (stextsel == 22) { StartStore(STORE_SMITH); @@ -1374,7 +1372,7 @@ void SmithBuyPItem() SpawnPremium(myplr); } -void S_SPBuyEnter() +void SmitPremiumBuyEnter() { if (stextsel == 22) { StartStore(STORE_SMITH); @@ -1519,7 +1517,7 @@ void StoreSellItem() } } -void S_SSellEnter() +void SmitSellEnter() { if (stextsel == 22) { StartStore(STORE_SMITH); @@ -1568,7 +1566,7 @@ void SmithRepairItem() myPlayer.InvList[i]._iDurability = myPlayer.InvList[i]._iMaxDur; } -void S_SRepairEnter() +void SmitRepairEnter() { if (stextsel == 22) { StartStore(STORE_SMITH); @@ -1591,7 +1589,7 @@ void S_SRepairEnter() StartStore(STORE_CONFIRM); } -void S_WitchEnter() +void WitchEnter() { switch (stextsel) { case 12: @@ -1646,7 +1644,7 @@ void WitchBuyItem() CalcPlrInv(myplr, true); } -void S_WBuyEnter() +void WitchBuyEnter() { if (stextsel == 22) { StartStore(STORE_WITCH); @@ -1679,7 +1677,7 @@ void S_WBuyEnter() NewCursor(CURSOR_HAND); } -void S_WSellEnter() +void WitchSellEnter() { if (stextsel == 22) { StartStore(STORE_WITCH); @@ -1720,7 +1718,7 @@ void WitchRechargeItem() CalcPlrInv(myplr, true); } -void S_WRechargeEnter() +void WitchRechargeEnter() { if (stextsel == 22) { StartStore(STORE_WITCH); @@ -1742,7 +1740,7 @@ void S_WRechargeEnter() StartStore(STORE_CONFIRM); } -void S_BoyEnter() +void BoyEnter() { if (!boyitem.isEmpty() && stextsel == 18) { if (plr[myplr]._pGold < 50) { @@ -1820,7 +1818,7 @@ void HealerBuyItem() CalcPlrInv(myplr, true); } -void S_BBuyEnter() +void BoyBuyEnter() { if (stextsel != 10) { stextflag = STORE_NONE; @@ -1861,7 +1859,7 @@ void S_BBuyEnter() NewCursor(CURSOR_HAND); } -void StoryIdItem() +void StorytellerIdentifyItem() { auto &myPlayer = plr[myplr]; @@ -1889,7 +1887,7 @@ void StoryIdItem() CalcPlrInv(myplr, true); } -void S_ConfirmEnter() +void ConfirmEnter() { if (stextsel == 18) { switch (stextshold) { @@ -1916,7 +1914,7 @@ void S_ConfirmEnter() HealerBuyItem(); break; case STORE_SIDENTIFY: - StoryIdItem(); + StorytellerIdentifyItem(); StartStore(STORE_IDSHOW); return; case STORE_SPBUY: @@ -1940,7 +1938,7 @@ void S_ConfirmEnter() } } -void S_HealerEnter() +void HealerEnter() { switch (stextsel) { case 12: @@ -1960,7 +1958,7 @@ void S_HealerEnter() } } -void S_HBuyEnter() +void HealerBuyEnter() { if (stextsel == 22) { StartStore(STORE_HEALER); @@ -1994,7 +1992,7 @@ void S_HBuyEnter() NewCursor(CURSOR_HAND); } -void S_StoryEnter() +void StorytellerEnter() { switch (stextsel) { case 12: @@ -2014,7 +2012,7 @@ void S_StoryEnter() } } -void S_SIDEnter() +void StorytellerIdentifyEnter() { if (stextsel == 22) { StartStore(STORE_STORY); @@ -2036,7 +2034,7 @@ void S_SIDEnter() StartStore(STORE_CONFIRM); } -void S_TalkEnter() +void TalkEnter() { if (stextsel == 22) { StartStore(stextshold); @@ -2074,7 +2072,7 @@ void S_TalkEnter() } } -void S_TavernEnter() +void TavernEnter() { switch (stextsel) { case 12: @@ -2091,7 +2089,7 @@ void S_TavernEnter() } } -void S_BarmaidEnter() +void BarmaidEnter() { switch (stextsel) { case 12: @@ -2108,7 +2106,7 @@ void S_BarmaidEnter() } } -void S_DrunkEnter() +void DrunkEnter() { switch (stextsel) { case 12: @@ -2125,6 +2123,27 @@ void S_DrunkEnter() } } +int TakeGold(PlayerStruct &player, int cost, bool skipMaxPiles) +{ + for (int i = 0; i < player._pNumInv; i++) { + auto &item = player.InvList[i]; + if (item._itype != ITYPE_GOLD || (skipMaxPiles && item._ivalue == MaxGold)) + continue; + + if (cost < item._ivalue) { + item._ivalue -= cost; + SetPlrHandGoldCurs(&player.InvList[i]); + return 0; + } + + cost -= item._ivalue; + player.RemoveInvItem(i); + i = -1; + } + + return cost; +} + } // namespace ItemStruct golditem; @@ -2314,79 +2333,79 @@ void StartStore(talk_id s) ReleaseStoreBtn(); switch (s) { case STORE_SMITH: - S_StartSmith(); + StartSmith(); break; case STORE_SBUY: if (storenumh > 0) - S_StartSBuy(); + StartSmithBuy(); else - S_StartSmith(); + StartSmith(); break; case STORE_SSELL: - S_StartSSell(); + StartSmithSell(); break; case STORE_SREPAIR: - S_StartSRepair(); + StartSmithRepair(); break; case STORE_WITCH: - S_StartWitch(); + StartWitch(); break; case STORE_WBUY: if (storenumh > 0) - S_StartWBuy(); + StartWitchBuy(); break; case STORE_WSELL: - S_StartWSell(); + StartWitchSell(); break; case STORE_WRECHARGE: - S_StartWRecharge(); + StartWitchRecharge(); break; case STORE_NOMONEY: - S_StartNoMoney(); + StoreNoMoney(); break; case STORE_NOROOM: - S_StartNoRoom(); + StoreNoRoom(); break; case STORE_CONFIRM: - S_StartConfirm(); + StoreConfirm(); break; case STORE_BOY: - S_StartBoy(); + StartBoy(); break; case STORE_BBOY: - S_StartBBoy(); + SStartBoyBuy(); break; case STORE_HEALER: - S_StartHealer(); + StartHealer(); break; case STORE_STORY: - S_StartStory(); + StartStoryteller(); break; case STORE_HBUY: if (storenumh > 0) - S_StartHBuy(); + StartHealerBuy(); break; case STORE_SIDENTIFY: - S_StartSIdentify(); + StartStorytellerIdentify(); break; case STORE_SPBUY: - if (!S_StartSPBuy()) + if (!StartSmithPremiumBuy()) return; break; case STORE_GOSSIP: - S_StartTalk(); + StartTalk(); break; case STORE_IDSHOW: - S_StartIdShow(); + StartStorytellerIdentifyShow(); break; case STORE_TAVERN: - S_StartTavern(); + StartTavern(); break; case STORE_DRUNK: - S_StartDrunk(); + StartDrunk(); break; case STORE_BARMAID: - S_StartBarMaid(); + StartBarmaid(); break; case STORE_NONE: break; @@ -2405,8 +2424,6 @@ void StartStore(talk_id s) void DrawSText(const Surface &out) { - int i; - if (!stextsize) DrawSTextBack(out); else @@ -2415,30 +2432,30 @@ void DrawSText(const Surface &out) if (stextscrl) { switch (stextflag) { case STORE_SBUY: - S_ScrollSBuy(stextsval); + ScrollSmithBuy(stextsval); break; case STORE_SSELL: case STORE_SREPAIR: case STORE_WSELL: case STORE_WRECHARGE: case STORE_SIDENTIFY: - S_ScrollSSell(stextsval); + ScrollSmithSell(stextsval); break; case STORE_WBUY: - S_ScrollWBuy(stextsval); + ScrollWitchBuy(stextsval); break; case STORE_HBUY: - S_ScrollHBuy(stextsval); + ScrollHealerBuy(stextsval); break; case STORE_SPBUY: - S_ScrollSPBuy(stextsval); + ScrollSmithPremiumBuy(stextsval); break; default: break; } } - for (i = 0; i < STORE_LINES; i++) { + for (int i = 0; i < STORE_LINES; i++) { if (stext[i]._sline != 0) DrawSLine(out, i); if (stext[i]._sstr[0] != '\0') @@ -2449,82 +2466,83 @@ void DrawSText(const Surface &out) DrawSSlider(out, 4, 20); } -void STextESC() +void StoreESC() { if (qtextflag) { qtextflag = false; if (leveltype == DTYPE_TOWN) stream_stop(); - } else { - switch (stextflag) { - case STORE_SMITH: - case STORE_WITCH: - case STORE_BOY: - case STORE_BBOY: - case STORE_HEALER: - case STORE_STORY: - case STORE_TAVERN: - case STORE_DRUNK: - case STORE_BARMAID: - stextflag = STORE_NONE; - break; - case STORE_GOSSIP: - StartStore(stextshold); - stextsel = stextlhold; - break; - case STORE_SBUY: - StartStore(STORE_SMITH); - stextsel = 12; - break; - case STORE_SPBUY: - StartStore(STORE_SMITH); - stextsel = 14; - break; - case STORE_SSELL: - StartStore(STORE_SMITH); - stextsel = 16; - break; - case STORE_SREPAIR: - StartStore(STORE_SMITH); - stextsel = 18; - break; - case STORE_WBUY: - StartStore(STORE_WITCH); - stextsel = 14; - break; - case STORE_WSELL: - StartStore(STORE_WITCH); - stextsel = 16; - break; - case STORE_WRECHARGE: - StartStore(STORE_WITCH); - stextsel = 18; - break; - case STORE_HBUY: - StartStore(STORE_HEALER); - stextsel = 16; - break; - case STORE_SIDENTIFY: - StartStore(STORE_STORY); - stextsel = 14; - break; - case STORE_IDSHOW: - StartStore(STORE_SIDENTIFY); - break; - case STORE_NOMONEY: - case STORE_NOROOM: - case STORE_CONFIRM: - StartStore(stextshold); - stextsel = stextlhold; - stextsval = stextvhold; - break; - case STORE_NONE: - break; - } + return; + } + + switch (stextflag) { + case STORE_SMITH: + case STORE_WITCH: + case STORE_BOY: + case STORE_BBOY: + case STORE_HEALER: + case STORE_STORY: + case STORE_TAVERN: + case STORE_DRUNK: + case STORE_BARMAID: + stextflag = STORE_NONE; + break; + case STORE_GOSSIP: + StartStore(stextshold); + stextsel = stextlhold; + break; + case STORE_SBUY: + StartStore(STORE_SMITH); + stextsel = 12; + break; + case STORE_SPBUY: + StartStore(STORE_SMITH); + stextsel = 14; + break; + case STORE_SSELL: + StartStore(STORE_SMITH); + stextsel = 16; + break; + case STORE_SREPAIR: + StartStore(STORE_SMITH); + stextsel = 18; + break; + case STORE_WBUY: + StartStore(STORE_WITCH); + stextsel = 14; + break; + case STORE_WSELL: + StartStore(STORE_WITCH); + stextsel = 16; + break; + case STORE_WRECHARGE: + StartStore(STORE_WITCH); + stextsel = 18; + break; + case STORE_HBUY: + StartStore(STORE_HEALER); + stextsel = 16; + break; + case STORE_SIDENTIFY: + StartStore(STORE_STORY); + stextsel = 14; + break; + case STORE_IDSHOW: + StartStore(STORE_SIDENTIFY); + break; + case STORE_NOMONEY: + case STORE_NOROOM: + case STORE_CONFIRM: + StartStore(stextshold); + stextsel = stextlhold; + stextsval = stextvhold; + break; + case STORE_NONE: + break; } } -void STextUp() +void StoreUp() { PlaySFX(IS_TITLEMOV); if (stextsel == -1) { @@ -2561,7 +2579,7 @@ void STextUp() } } -void STextDown() +void StoreDown() { PlaySFX(IS_TITLEMOV); if (stextsel == -1) { @@ -2598,7 +2616,7 @@ void STextDown() } } -void STextPrior() +void StorePrior() { PlaySFX(IS_TITLEMOV); if (stextsel != -1 && stextscrl) { @@ -2613,7 +2631,7 @@ void STextPrior() } } -void STextNext() +void StoreNext() { PlaySFX(IS_TITLEMOV); if (stextsel != -1 && stextscrl) { @@ -2628,27 +2646,6 @@ void STextNext() } } -static int TakeGold(PlayerStruct &player, int cost, bool skipMaxPiles) -{ - for (int i = 0; i < player._pNumInv; i++) { - auto &item = player.InvList[i]; - if (item._itype != ITYPE_GOLD || (skipMaxPiles && item._ivalue == MaxGold)) - continue; - - if (cost < item._ivalue) { - item._ivalue -= cost; - SetPlrHandGoldCurs(&player.InvList[i]); - return 0; - } - - cost -= item._ivalue; - player.RemoveInvItem(i); - i = -1; - } - - return cost; -} - void TakePlrsMoney(int cost) { auto &myPlayer = plr[myplr]; @@ -2661,7 +2658,7 @@ void TakePlrsMoney(int cost) } } -void STextEnter() +void StoreEnter() { if (qtextflag) { qtextflag = false; @@ -2674,31 +2671,31 @@ void STextEnter() PlaySFX(IS_TITLSLCT); switch (stextflag) { case STORE_SMITH: - S_SmithEnter(); + SmithEnter(); break; case STORE_SPBUY: - S_SPBuyEnter(); + SmitPremiumBuyEnter(); break; case STORE_SBUY: - S_SBuyEnter(); + SmitBuyEnter(); break; case STORE_SSELL: - S_SSellEnter(); + SmitSellEnter(); break; case STORE_SREPAIR: - S_SRepairEnter(); + SmitRepairEnter(); break; case STORE_WITCH: - S_WitchEnter(); + WitchEnter(); break; case STORE_WBUY: - S_WBuyEnter(); + WitchBuyEnter(); break; case STORE_WSELL: - S_WSellEnter(); + WitchSellEnter(); break; case STORE_WRECHARGE: - S_WRechargeEnter(); + WitchRechargeEnter(); break; case STORE_NOMONEY: case STORE_NOROOM: @@ -2707,40 +2704,40 @@ void STextEnter() stextsval = stextvhold; break; case STORE_CONFIRM: - S_ConfirmEnter(); + ConfirmEnter(); break; case STORE_BOY: - S_BoyEnter(); + BoyEnter(); break; case STORE_BBOY: - S_BBuyEnter(); + BoyBuyEnter(); break; case STORE_HEALER: - S_HealerEnter(); + HealerEnter(); break; case STORE_STORY: - S_StoryEnter(); + StorytellerEnter(); break; case STORE_HBUY: - S_HBuyEnter(); + HealerBuyEnter(); break; case STORE_SIDENTIFY: - S_SIDEnter(); + StorytellerIdentifyEnter(); break; case STORE_GOSSIP: - S_TalkEnter(); + TalkEnter(); break; case STORE_IDSHOW: StartStore(STORE_SIDENTIFY); break; case STORE_DRUNK: - S_DrunkEnter(); + DrunkEnter(); break; case STORE_TAVERN: - S_TavernEnter(); + TavernEnter(); break; case STORE_BARMAID: - S_BarmaidEnter(); + BarmaidEnter(); break; case STORE_NONE: break; @@ -2749,8 +2746,6 @@ void STextEnter() void CheckStoreBtn() { - int y; - if (qtextflag) { qtextflag = false; if (leveltype == DTYPE_TOWN) @@ -2763,11 +2758,11 @@ void CheckStoreBtn() if (MousePosition.x < 24 + PANEL_LEFT || MousePosition.x > 616 + PANEL_LEFT) return; } - y = (MousePosition.y - (32 + UI_OFFSET_Y)) / 12; + int y = (MousePosition.y - (32 + UI_OFFSET_Y)) / 12; if (stextscrl && MousePosition.x > 600 + PANEL_LEFT) { if (y == 4) { if (stextscrlubtn <= 0) { - STextUp(); + StoreUp(); stextscrlubtn = 10; } else { stextscrlubtn--; @@ -2775,7 +2770,7 @@ void CheckStoreBtn() } if (y == 20) { if (stextscrldbtn <= 0) { - STextDown(); + StoreDown(); stextscrldbtn = 10; } else { stextscrldbtn--; @@ -2793,7 +2788,7 @@ void CheckStoreBtn() } if (stext[y]._ssel || (stextscrl && y == 22)) { stextsel = y; - STextEnter(); + StoreEnter(); } } } diff --git a/Source/stores.h b/Source/stores.h index 5981689f9..a067d1193 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -104,13 +104,13 @@ void DrawSTextHelp(); void ClearSText(int s, int e); void StartStore(talk_id s); void DrawSText(const Surface &out); -void STextESC(); -void STextUp(); -void STextDown(); -void STextPrior(); -void STextNext(); +void StoreESC(); +void StoreUp(); +void StoreDown(); +void StorePrior(); +void StoreNext(); void TakePlrsMoney(int cost); -void STextEnter(); +void StoreEnter(); void CheckStoreBtn(); void ReleaseStoreBtn();