From 20262e45691a91b1608930c3c0f4eaee1301a5fc Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 8 Jul 2021 02:10:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Move=20local=20symbols=20in=20to?= =?UTF-8?q?=20anon=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/capture.cpp | 2 + Source/codec.cpp | 2 + Source/control.cpp | 570 ++++++------- Source/debug.cpp | 84 +- Source/diablo.cpp | 1907 ++++++++++++++++++++++---------------------- Source/drlg_l1.cpp | 676 ++++++++-------- Source/drlg_l1.h | 9 - 7 files changed, 1620 insertions(+), 1630 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index a1325f2b8..32543ce3a 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -16,6 +16,7 @@ #include "utils/ui_fwd.h" namespace devilution { +namespace { /** * @brief Write the PCX-file header @@ -156,6 +157,7 @@ static void RedPalette() BltFast(nullptr, nullptr); RenderPresent(); } +} /** * @brief Save the current screen to a screen??.PCX (00-99) in file if available, then make the screen red for 200ms. diff --git a/Source/codec.cpp b/Source/codec.cpp index dad97842c..5bdeda28c 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -12,6 +12,7 @@ #include "utils/stdcompat/cstddef.hpp" namespace devilution { +namespace { struct CodecSignature { uint32_t checksum; @@ -53,6 +54,7 @@ static void CodecInitKey(const char *pszPassword) } memset(key, 0, sizeof(key)); } +} std::size_t codec_decode(byte *pbSrcDst, std::size_t size, const char *pszPassword) { diff --git a/Source/control.cpp b/Source/control.cpp index 52091e906..f9f5f4494 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -32,50 +32,24 @@ #include "utils/sdl_geometry.h" namespace devilution { -namespace { -Surface pBtmBuff; -Surface pLifeBuff; -Surface pManaBuff; -std::optional talkButtons; -std::optional pDurIcons; -std::optional pChrButtons; -std::optional multiButtons; -std::optional pPanelButtons; -std::optional pChrPanel; -std::optional pGBoxBuff; -std::optional pSBkBtnCel; -std::optional pSBkIconCels; -std::optional pSpellBkCel; -std::optional pSpellCels; -} // namespace - -BYTE sgbNextTalkSave; -BYTE sgbTalkSavePos; - /** * @brief Set if the life flask needs to be redrawn during next frame -*/ + */ bool drawhpflag; bool dropGoldFlag; -bool panbtns[8]; bool chrbtn[4]; bool lvlbtndown; -char sgszTalkSave[8][80]; int dropGoldValue; /** * @brief Set if the mana flask needs to be redrawn during the next frame -*/ + */ bool drawmanaflag; bool chrbtnactive; -char sgszTalkMsg[MAX_SEND_STR_LEN]; int pnumlines; bool pinfoflag; -bool talkButtonsDown[3]; spell_id pSpell; uint16_t infoclr; -int sgbPlrTalkTbl; char tempstr[256]; -bool whisperList[MAX_PLRS]; int sbooktab; spell_type pSplType; int initialDropGoldIndex; @@ -84,16 +58,51 @@ bool sbookflag; bool chrflag; bool drawbtnflag; char infostr[64]; -int numpanbtns; -char panelstr[4][64]; bool panelflag; -uint8_t SplTransTbl[256]; int initialDropGoldValue; bool panbtndown; bool spselflag; extern std::array quickSpellActionIndexes; +/** Maps from attribute_id to the rectangle on screen used for attribute increment buttons. */ +Rectangle ChrBtnsRect[4] = { + { { 137, 138 }, { 41, 22 } }, + { { 137, 166 }, { 41, 22 } }, + { { 137, 195 }, { 41, 22 } }, + { { 137, 223 }, { 41, 22 } } +}; + +namespace { + +Surface pBtmBuff; +Surface pLifeBuff; +Surface pManaBuff; +std::optional talkButtons; +std::optional pDurIcons; +std::optional pChrButtons; +std::optional multiButtons; +std::optional pPanelButtons; +std::optional pChrPanel; +std::optional pGBoxBuff; +std::optional pSBkBtnCel; +std::optional pSBkIconCels; +std::optional pSpellBkCel; +std::optional pSpellCels; + +BYTE sgbNextTalkSave; +BYTE sgbTalkSavePos; + +bool panbtns[8]; +char sgszTalkSave[8][80]; +char sgszTalkMsg[MAX_SEND_STR_LEN]; +bool talkButtonsDown[3]; +int sgbPlrTalkTbl; +bool whisperList[MAX_PLRS]; +int numpanbtns; +char panelstr[4][64]; +uint8_t SplTransTbl[256]; + /** Map of hero class names */ const char *const ClassStrTbl[] = { N_("Warrior"), @@ -210,13 +219,6 @@ const char *const PanBtnStr[8] = { N_("Send Message"), "" // Player attack }; -/** Maps from attribute_id to the rectangle on screen used for attribute increment buttons. */ -Rectangle ChrBtnsRect[4] = { - { { 137, 138 }, { 41, 22 } }, - { { 137, 166 }, { 41, 22 } }, - { { 137, 195 }, { 41, 22 } }, - { { 137, 223 }, { 41, 22 } } -}; /** Maps from spellbook page number and position to spell_id. */ spell_id SpellPages[6][7] = { @@ -292,15 +294,256 @@ void SetSpellTrans(spell_type t) SplTransTbl[PAL16_YELLOW - PAL16_GRAY + i] = i; SplTransTbl[PAL16_ORANGE - PAL16_GRAY + i] = i; } - SplTransTbl[PAL16_BEIGE + 15] = 0; - SplTransTbl[PAL16_YELLOW + 15] = 0; - SplTransTbl[PAL16_ORANGE + 15] = 0; - break; - case RSPLTYPE_SKILL: - break; + SplTransTbl[PAL16_BEIGE + 15] = 0; + SplTransTbl[PAL16_YELLOW + 15] = 0; + SplTransTbl[PAL16_ORANGE + 15] = 0; + break; + case RSPLTYPE_SKILL: + break; + } +} + +static void PrintSBookHotkey(const Surface &out, Point position, const std::string &text) +{ + // Align the hot key text with the top-right corner of the spell icon + position += Displacement { SPLICONLENGTH - (GetLineWidth(text.c_str()) + 5), 17 - SPLICONLENGTH }; + + // Draw a drop shadow below and to the left of the text + DrawString(out, text.c_str(), position + Displacement { -1, 1 }, UIS_BLACK); + // Then draw the text over the top + DrawString(out, text.c_str(), position, UIS_SILVER); +} + +/** + * Draws a section of the empty flask cel on top of the panel to create the illusion + * of the flask getting empty. This function takes a cel and draws a + * horizontal stripe of height (max-min) onto the given buffer. + * @param out Target buffer. + * @param position Buffer coordinate. + * @param celBuf Buffer of the empty flask cel. + * @param y0 Top of the flask cel section to draw. + * @param y1 Bottom of the flask cel section to draw. + */ +static void DrawFlaskTop(const Surface &out, Point position, const Surface &celBuf, int y0, int y1) +{ + out.BlitFrom(celBuf, SDL_Rect { 0, static_cast(y0), celBuf.w(), y1 - y0 }, position); +} + +/** + * Draws the dome of the flask that protrudes above the panel top line. + * It draws a rectangle of fixed width 59 and height 'h' from the source buffer + * into the target buffer. + * @param out The target buffer. + * @param celBuf Buffer of the empty flask cel. + * @param sourcePosition Source buffer start coordinate. + * @param targetPosition Target buffer coordinate. + * @param h How many lines of the source buffer that will be copied. + */ +static void DrawFlask(const Surface &out, const Surface &celBuf, Point sourcePosition, Point targetPosition, int h) +{ + constexpr int FlaskWidth = 59; + out.BlitFromSkipColorIndexZero(celBuf, MakeSdlRect(sourcePosition.x, sourcePosition.y, FlaskWidth, h), targetPosition); +} + +/** + * @brief Draws the part of the life/mana flasks protruding above the bottom panel + * @see DrawFlaskLower() + * @param out The display region to draw to + * @param sourceBuffer A sprite representing the appropriate background/empty flask style + * @param offset X coordinate offset for where the flask should be drawn + * @param fillPer How full the flask is (a value from 0 to 80) + */ +void DrawFlaskUpper(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) +{ + // clamping because this function only draws the top 12% of the flask display + int emptyPortion = clamp(80 - fillPer, 0, 11) + 2; // +2 to account for the frame being included in the sprite + + // Draw the empty part of the flask + DrawFlask(out, sourceBuffer, { 13, 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 }, emptyPortion); + if (emptyPortion < 13) + // Draw the filled part of the flask + DrawFlask(out, pBtmBuff, { offset, emptyPortion + 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 + emptyPortion }, 13 - emptyPortion); +} + +/** + * @brief Draws the part of the life/mana flasks inside the bottom panel + * @see DrawFlaskUpper() + * @param out The display region to draw to + * @param sourceBuffer A sprite representing the appropriate background/empty flask style + * @param offset X coordinate offset for where the flask should be drawn + * @param fillPer How full the flask is (a value from 0 to 80) + */ +void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) +{ + int filled = clamp(fillPer, 0, 69); + + if (filled < 69) + DrawFlaskTop(out, { PANEL_X + offset, PANEL_Y }, sourceBuffer, 16, 85 - filled); + + // It appears that the panel defaults to having a filled flask and DrawFlaskTop only overlays the appropriate amount of empty space. + // This draw might not be necessary? + if (filled > 0) + DrawPanelBox(out, { offset, 85 - filled, 88, filled }, { PANEL_X + offset, PANEL_Y + 69 - filled }); +} + +void control_set_button_down(int btnId) +{ + panbtns[btnId] = true; + drawbtnflag = true; + panbtndown = true; +} + +static void PrintInfo(const Surface &out) +{ + if (talkflag) + return; + + Rectangle line { { PANEL_X + 177, PANEL_Y + LineOffsets[pnumlines][0] }, { 288, 0 } }; + + int yo = 0; + int lo = 1; + if (infostr[0] != '\0') { + DrawString(out, infostr, line, infoclr | UIS_CENTER | UIS_FIT_SPACING, 2); + yo = 1; + lo = 0; + } + + for (int i = 0; i < pnumlines; i++) { + line.position.y = PANEL_Y + LineOffsets[pnumlines - lo][i + yo]; + DrawString(out, panelstr[i], line, infoclr | UIS_CENTER | UIS_FIT_SPACING, 2); + } +} + +int CapStatPointsToAdd(int remainingStatPoints, const PlayerStruct &player, CharacterAttribute attribute) +{ + int pointsToReachCap = player.GetMaximumAttributeValue(attribute) - player.GetBaseAttributeValue(attribute); + + return std::min(remainingStatPoints, pointsToReachCap); +} + +static int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c) +{ + if (pItem->isEmpty()) + return x; + if (pItem->_iDurability > 5) + return x; + if (c == 0) { + switch (pItem->_itype) { + case ITYPE_SWORD: + c = 2; + break; + case ITYPE_AXE: + c = 6; + break; + case ITYPE_BOW: + c = 7; + break; + case ITYPE_MACE: + c = 5; + break; + case ITYPE_STAFF: + c = 8; + break; + default: + c = 1; + break; + } + } + if (pItem->_iDurability > 2) + c += 8; + CelDrawTo(out, { x, -17 + PANEL_Y }, *pDurIcons, c); + return x - 32 - 8; +} + +static void PrintSBookStr(const Surface &out, Point position, const char *text) +{ + DrawString(out, text, { { RIGHT_PANEL_X + SPLICONLENGTH + position.x, position.y }, { 222, 0 } }, UIS_SILVER); +} + +spell_type GetSBookTrans(spell_id ii, bool townok) +{ + auto &myPlayer = Players[MyPlayerId]; + if ((myPlayer._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) + return RSPLTYPE_SKILL; + spell_type st = RSPLTYPE_SPELL; + if ((myPlayer._pISpells & GetSpellBitmask(ii)) != 0) { + st = RSPLTYPE_CHARGES; + } + if ((myPlayer._pAblSpells & GetSpellBitmask(ii)) != 0) { + st = RSPLTYPE_SKILL; + } + if (st == RSPLTYPE_SPELL) { + if (!CheckSpell(MyPlayerId, ii, st, true)) { + st = RSPLTYPE_INVALID; + } + if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) { + st = RSPLTYPE_INVALID; + } + } + if (townok && currlevel == 0 && st != RSPLTYPE_INVALID && !spelldata[ii].sTownSpell) { + st = RSPLTYPE_INVALID; + } + + return st; +} + +static void ControlSetGoldCurs(PlayerStruct &player) +{ + SetPlrHandGoldCurs(&player.HoldItem); + NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); +} + +void control_reset_talk_msg() +{ + uint32_t pmask = 0; + + for (int i = 0; i < MAX_PLRS; i++) { + if (whisperList[i]) + pmask |= 1 << i; + } + NetSendCmdString(pmask, sgszTalkMsg); +} + +static void ControlPressEnter() +{ + if (sgszTalkMsg[0] != 0) { + control_reset_talk_msg(); + int i = 0; + for (; i < 8; i++) { + if (strcmp(sgszTalkSave[i], sgszTalkMsg) == 0) + break; + } + if (i >= 8) { + strcpy(sgszTalkSave[sgbNextTalkSave], sgszTalkMsg); + sgbNextTalkSave++; + sgbNextTalkSave &= 7; + } else { + BYTE talkSave = sgbNextTalkSave - 1; + talkSave &= 7; + if (i != talkSave) { + strcpy(sgszTalkSave[i], sgszTalkSave[talkSave]); + strcpy(sgszTalkSave[talkSave], sgszTalkMsg); + } + } + sgszTalkMsg[0] = '\0'; + sgbTalkSavePos = sgbNextTalkSave; + } + control_reset_talk(); +} + +static void ControlUpDown(int v) +{ + for (int i = 0; i < 8; i++) { + sgbTalkSavePos = (v + sgbTalkSavePos) & 7; + if (sgszTalkSave[sgbTalkSavePos][0] != 0) { + strcpy(sgszTalkMsg, sgszTalkSave[sgbTalkSavePos]); + return; + } } } +} // namespace + void DrawSpell(const Surface &out) { auto &myPlayer = Players[MyPlayerId]; @@ -323,17 +566,6 @@ void DrawSpell(const Surface &out) DrawSpellCel(out, position, *pSpellCels, nCel); } -static void PrintSBookHotkey(const Surface &out, Point position, const std::string &text) -{ - // Align the hot key text with the top-right corner of the spell icon - position += Displacement { SPLICONLENGTH - (GetLineWidth(text.c_str()) + 5), 17 - SPLICONLENGTH }; - - // Draw a drop shadow below and to the left of the text - DrawString(out, text.c_str(), position + Displacement { -1, 1 }, UIS_BLACK); - // Then draw the text over the top - DrawString(out, text.c_str(), position, UIS_SILVER); -} - void DrawSpellList(const Surface &out) { int c; @@ -550,78 +782,6 @@ void DrawPanelBox(const Surface &out, SDL_Rect srcRect, Point targetPosition) out.BlitFrom(pBtmBuff, srcRect, targetPosition); } -/** - * Draws a section of the empty flask cel on top of the panel to create the illusion - * of the flask getting empty. This function takes a cel and draws a - * horizontal stripe of height (max-min) onto the given buffer. - * @param out Target buffer. - * @param position Buffer coordinate. - * @param celBuf Buffer of the empty flask cel. - * @param y0 Top of the flask cel section to draw. - * @param y1 Bottom of the flask cel section to draw. - */ -static void DrawFlaskTop(const Surface &out, Point position, const Surface &celBuf, int y0, int y1) -{ - out.BlitFrom(celBuf, SDL_Rect { 0, static_cast(y0), celBuf.w(), y1 - y0 }, position); -} - -/** - * Draws the dome of the flask that protrudes above the panel top line. - * It draws a rectangle of fixed width 59 and height 'h' from the source buffer - * into the target buffer. - * @param out The target buffer. - * @param celBuf Buffer of the empty flask cel. - * @param sourcePosition Source buffer start coordinate. - * @param targetPosition Target buffer coordinate. - * @param h How many lines of the source buffer that will be copied. - */ -static void DrawFlask(const Surface &out, const Surface &celBuf, Point sourcePosition, Point targetPosition, int h) -{ - constexpr int FlaskWidth = 59; - out.BlitFromSkipColorIndexZero(celBuf, MakeSdlRect(sourcePosition.x, sourcePosition.y, FlaskWidth, h), targetPosition); -} - -/** - * @brief Draws the part of the life/mana flasks protruding above the bottom panel - * @see DrawFlaskLower() - * @param out The display region to draw to - * @param sourceBuffer A sprite representing the appropriate background/empty flask style - * @param offset X coordinate offset for where the flask should be drawn - * @param fillPer How full the flask is (a value from 0 to 80) - */ -void DrawFlaskUpper(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) -{ - // clamping because this function only draws the top 12% of the flask display - int emptyPortion = clamp(80 - fillPer, 0, 11) + 2; // +2 to account for the frame being included in the sprite - - // Draw the empty part of the flask - DrawFlask(out, sourceBuffer, { 13, 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 }, emptyPortion); - if (emptyPortion < 13) - // Draw the filled part of the flask - DrawFlask(out, pBtmBuff, { offset, emptyPortion + 3 }, { PANEL_LEFT + offset, PANEL_TOP - 13 + emptyPortion }, 13 - emptyPortion); -} - -/** - * @brief Draws the part of the life/mana flasks inside the bottom panel - * @see DrawFlaskUpper() - * @param out The display region to draw to - * @param sourceBuffer A sprite representing the appropriate background/empty flask style - * @param offset X coordinate offset for where the flask should be drawn - * @param fillPer How full the flask is (a value from 0 to 80) - */ -void DrawFlaskLower(const Surface &out, const Surface &sourceBuffer, int offset, int fillPer) -{ - int filled = clamp(fillPer, 0, 69); - - if (filled < 69) - DrawFlaskTop(out, { PANEL_X + offset, PANEL_Y }, sourceBuffer, 16, 85 - filled); - - // It appears that the panel defaults to having a filled flask and DrawFlaskTop only overlays the appropriate amount of empty space. - // This draw might not be necessary? - if (filled > 0) - DrawPanelBox(out, { offset, 85 - filled, 88, filled }, { PANEL_X + offset, PANEL_Y + 69 - filled }); -} - void DrawLifeFlaskUpper(const Surface &out) { constexpr int LifeFlaskUpperOffset = 109; @@ -849,13 +1009,6 @@ void DoPanBtn() } } -void control_set_button_down(int btnId) -{ - panbtns[btnId] = true; - drawbtnflag = true; - panbtndown = true; -} - void control_check_btn_press() { int x = PanBtnPos[3].x + PANEL_LEFT + PanBtnPos[3].w; @@ -1080,27 +1233,6 @@ void FreeControlPan() pGBoxBuff = std::nullopt; } -static void PrintInfo(const Surface &out) -{ - if (talkflag) - return; - - Rectangle line { { PANEL_X + 177, PANEL_Y + LineOffsets[pnumlines][0] }, { 288, 0 } }; - - int yo = 0; - int lo = 1; - if (infostr[0] != '\0') { - DrawString(out, infostr, line, infoclr | UIS_CENTER | UIS_FIT_SPACING, 2); - yo = 1; - lo = 0; - } - - for (int i = 0; i < pnumlines; i++) { - line.position.y = PANEL_Y + LineOffsets[pnumlines - lo][i + yo]; - DrawString(out, panelstr[i], line, infoclr | UIS_CENTER | UIS_FIT_SPACING, 2); - } -} - void DrawInfoBox(const Surface &out) { DrawPanelBox(out, { 177, 62, 288, 60 }, { PANEL_X + 177, PANEL_Y + 46 }); @@ -1430,13 +1562,6 @@ void CheckChrBtns() } } -int CapStatPointsToAdd(int remainingStatPoints, const PlayerStruct &player, CharacterAttribute attribute) -{ - int pointsToReachCap = player.GetMaximumAttributeValue(attribute) - player.GetBaseAttributeValue(attribute); - - return std::min(remainingStatPoints, pointsToReachCap); -} - void ReleaseChrBtns(bool addAllStatPoints) { chrbtnactive = false; @@ -1473,40 +1598,6 @@ void ReleaseChrBtns(bool addAllStatPoints) } } -static int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c) -{ - if (pItem->isEmpty()) - return x; - if (pItem->_iDurability > 5) - return x; - if (c == 0) { - switch (pItem->_itype) { - case ITYPE_SWORD: - c = 2; - break; - case ITYPE_AXE: - c = 6; - break; - case ITYPE_BOW: - c = 7; - break; - case ITYPE_MACE: - c = 5; - break; - case ITYPE_STAFF: - c = 8; - break; - default: - c = 1; - break; - } - } - if (pItem->_iDurability > 2) - c += 8; - CelDrawTo(out, { x, -17 + PANEL_Y }, *pDurIcons, c); - return x - 32 - 8; -} - void DrawDurIcon(const Surface &out) { bool hasRoomBetweenPanels = gnScreenWidth >= PANEL_WIDTH + 16 + (32 + 8 + 32 + 8 + 32 + 8 + 32) + 16; @@ -1543,38 +1634,6 @@ void RedBack(const Surface &out) } } -static void PrintSBookStr(const Surface &out, Point position, const char *text) -{ - DrawString(out, text, { { RIGHT_PANEL_X + SPLICONLENGTH + position.x, position.y }, { 222, 0 } }, UIS_SILVER); -} - -spell_type GetSBookTrans(spell_id ii, bool townok) -{ - auto &myPlayer = Players[MyPlayerId]; - if ((myPlayer._pClass == HeroClass::Monk) && (ii == SPL_SEARCH)) - return RSPLTYPE_SKILL; - spell_type st = RSPLTYPE_SPELL; - if ((myPlayer._pISpells & GetSpellBitmask(ii)) != 0) { - st = RSPLTYPE_CHARGES; - } - if ((myPlayer._pAblSpells & GetSpellBitmask(ii)) != 0) { - st = RSPLTYPE_SKILL; - } - if (st == RSPLTYPE_SPELL) { - if (!CheckSpell(MyPlayerId, ii, st, true)) { - st = RSPLTYPE_INVALID; - } - if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) { - st = RSPLTYPE_INVALID; - } - } - if (townok && currlevel == 0 && st != RSPLTYPE_INVALID && !spelldata[ii].sTownSpell) { - st = RSPLTYPE_INVALID; - } - - return st; -} - void DrawSpellBook(const Surface &out) { CelDrawTo(out, { RIGHT_PANEL_X, 351 }, *pSpellBkCel, 1); @@ -1743,12 +1802,6 @@ void control_drop_gold(char vkey) } } -static void ControlSetGoldCurs(PlayerStruct &player) -{ - SetPlrHandGoldCurs(&player.HoldItem); - NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); -} - void control_remove_gold(int pnum, int goldIndex) { auto &player = Players[pnum]; @@ -1866,17 +1919,6 @@ void control_release_talk_btn() whisperList[p - 1] = !whisperList[p - 1]; } -void control_reset_talk_msg() -{ - uint32_t pmask = 0; - - for (int i = 0; i < MAX_PLRS; i++) { - if (whisperList[i]) - pmask |= 1 << i; - } - NetSendCmdString(pmask, sgszTalkMsg); -} - void control_type_message() { if (!gbIsMultiplayer) @@ -1899,33 +1941,6 @@ void control_reset_talk() force_redraw = 255; } -static void ControlPressEnter() -{ - if (sgszTalkMsg[0] != 0) { - control_reset_talk_msg(); - int i = 0; - for (; i < 8; i++) { - if (strcmp(sgszTalkSave[i], sgszTalkMsg) == 0) - break; - } - if (i >= 8) { - strcpy(sgszTalkSave[sgbNextTalkSave], sgszTalkMsg); - sgbNextTalkSave++; - sgbNextTalkSave &= 7; - } else { - BYTE talkSave = sgbNextTalkSave - 1; - talkSave &= 7; - if (i != talkSave) { - strcpy(sgszTalkSave[i], sgszTalkSave[talkSave]); - strcpy(sgszTalkSave[talkSave], sgszTalkMsg); - } - } - sgszTalkMsg[0] = '\0'; - sgbTalkSavePos = sgbNextTalkSave; - } - control_reset_talk(); -} - bool control_talk_last_key(int vkey) { if (!gbIsMultiplayer) @@ -1945,17 +1960,6 @@ bool control_talk_last_key(int vkey) return true; } -static void ControlUpDown(int v) -{ - for (int i = 0; i < 8; i++) { - sgbTalkSavePos = (v + sgbTalkSavePos) & 7; - if (sgszTalkSave[sgbTalkSavePos][0] != 0) { - strcpy(sgszTalkMsg, sgszTalkSave[sgbTalkSavePos]); - return; - } - } -} - bool control_presskeys(int vkey) { if (!gbIsMultiplayer) diff --git a/Source/debug.cpp b/Source/debug.cpp index b1c9fb3a3..f8b977857 100644 --- a/Source/debug.cpp +++ b/Source/debug.cpp @@ -14,17 +14,53 @@ namespace devilution { +std::optional pSquareCel; + #ifdef _DEBUG -#define DebugSeeds 4096 -int seed_index; -int level_seeds[NUMLEVELS + 1]; -int seed_table[DebugSeeds]; +namespace { -std::optional pSquareCel; char dMonsDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; char dFlagDbg[NUMLEVELS][MAXDUNX][MAXDUNY]; +int DebugPlayerId; +int DebugQuestId; +int DebugMonsterId; + +void SetSpellLevelCheat(spell_id spl, int spllvl) +{ + auto &myPlayer = Players[MyPlayerId]; + + myPlayer._pMemSpells |= GetSpellBitmask(spl); + myPlayer._pSplLvl[spl] = spllvl; +} + +void PrintDebugMonster(int m) +{ + char dstr[128]; + + sprintf(dstr, "Monster %i = %s", m, _(Monsters[m].mName)); + NetSendCmdString(1 << MyPlayerId, dstr); + sprintf(dstr, "X = %i, Y = %i", Monsters[m].position.tile.x, Monsters[m].position.tile.y); + NetSendCmdString(1 << MyPlayerId, dstr); + sprintf(dstr, "Enemy = %i, HP = %i", Monsters[m]._menemy, Monsters[m]._mhitpoints); + NetSendCmdString(1 << MyPlayerId, dstr); + sprintf(dstr, "Mode = %i, Var1 = %i", Monsters[m]._mmode, Monsters[m]._mVar1); + NetSendCmdString(1 << MyPlayerId, dstr); + + bool bActive = false; + + for (int i = 0; i < ActiveMonsterCount; i++) { + if (ActiveMonsters[i] == m) + bActive = true; + } + + sprintf(dstr, "Active List = %i, Squelch = %i", bActive ? 1 : 0, Monsters[m]._msquelch); + NetSendCmdString(1 << MyPlayerId, dstr); +} + +} + void LoadDebugGFX() { if (visiondebug) @@ -99,14 +135,6 @@ void MaxSpellsCheat() } } -void SetSpellLevelCheat(spell_id spl, int spllvl) -{ - auto &myPlayer = Players[MyPlayerId]; - - myPlayer._pMemSpells |= GetSpellBitmask(spl); - myPlayer._pSplLvl[spl] = spllvl; -} - void SetAllSpellsCheat() { SetSpellLevelCheat(SPL_FIREBOLT, 8); @@ -133,8 +161,6 @@ void SetAllSpellsCheat() SetSpellLevelCheat(SPL_BONESPIRIT, 1); } -int DebugPlayerId; - void PrintDebugPlayer(bool bNextPlayer) { char dstr[128]; @@ -162,8 +188,6 @@ void PrintDebugPlayer(bool bNextPlayer) } } -int DebugQuestId; - void PrintDebugQuest() { char dstr[128]; @@ -176,32 +200,6 @@ void PrintDebugQuest() DebugQuestId = 0; } -void PrintDebugMonster(int m) -{ - char dstr[128]; - - sprintf(dstr, "Monster %i = %s", m, _(Monsters[m].mName)); - NetSendCmdString(1 << MyPlayerId, dstr); - sprintf(dstr, "X = %i, Y = %i", Monsters[m].position.tile.x, Monsters[m].position.tile.y); - NetSendCmdString(1 << MyPlayerId, dstr); - sprintf(dstr, "Enemy = %i, HP = %i", Monsters[m]._menemy, Monsters[m]._mhitpoints); - NetSendCmdString(1 << MyPlayerId, dstr); - sprintf(dstr, "Mode = %i, Var1 = %i", Monsters[m]._mmode, Monsters[m]._mVar1); - NetSendCmdString(1 << MyPlayerId, dstr); - - bool bActive = false; - - for (int i = 0; i < ActiveMonsterCount; i++) { - if (ActiveMonsters[i] == m) - bActive = true; - } - - sprintf(dstr, "Active List = %i, Squelch = %i", bActive ? 1 : 0, Monsters[m]._msquelch); - NetSendCmdString(1 << MyPlayerId, dstr); -} - -int DebugMonsterId; - void GetDebugMonster() { int mi1 = pcursmonst; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index c1d45b61b..8471377c7 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -74,15 +74,7 @@ namespace devilution { SDL_Window *ghMainWnd; DWORD glSeedTbl[NUMLEVELS]; dungeon_type gnLevelTypeTbl[NUMLEVELS]; - -// Used for debugging level generation -uint32_t glEndSeed[NUMLEVELS]; -uint32_t glMid1Seed[NUMLEVELS]; -uint32_t glMid2Seed[NUMLEVELS]; -uint32_t glMid3Seed[NUMLEVELS]; - Point MousePosition; -bool gbGameLoopStartup; bool gbRunGame; bool gbRunGameResult; bool zoomflag; @@ -91,18 +83,14 @@ bool gbProcessPlayers; bool gbLoadGame; bool cineflag; int force_redraw; -int setseed; int PauseMode; -bool forceSpawn; -bool forceDiablo; bool gbNestArt; bool gbBard; bool gbBarbarian; bool gbQuietMode = false; -int sgnTimeoutCurs; clicktype sgbMouseDown; -int color_cycle_timer; uint16_t gnTickDelay = 50; +char gszProductName[64] = "DevilutionX vUnknown"; Keymapper keymapper { // Workaround: remove once the INI library has been replaced. [](const std::string &key, const std::string &value) { @@ -117,10 +105,7 @@ Keymapper keymapper { }; std::array quickSpellActionIndexes; -/* rdata */ - bool gbForceWindowed = false; -bool gbShowIntro = true; bool leveldebug = false; #ifdef _DEBUG bool monstdebug = false; @@ -128,13 +113,11 @@ _monster_id DebugMonsters[10]; int debugmonsttypes = 0; bool visiondebug = false; int questdebug = -1; -bool debug_mode_key_s = false; bool debug_mode_key_w = false; bool debug_mode_key_inverted_v = false; bool debug_mode_dollar_sign = false; bool debug_mode_key_i = false; int debug_mode_key_j = 0; -int arrowdebug = 0; #endif /** Specifies whether players are in non-PvP mode. */ bool gbFriendlyMode = true; @@ -146,146 +129,36 @@ QuickMessage QuickMessages[QUICK_MESSAGE_OPTIONS] = { { "QuickMessage4", N_("Now you DIE!") } }; -/** To know if these things have been done when we get to the diablo_deinit() function */ -bool was_archives_init = false; -/** To know if surfaces have been initialized or not */ -bool was_window_init = false; -bool was_ui_init = false; -bool was_snd_init = false; - -// Controller support: +// Controller support: Actions to run after updating the cursor state. +// Defined in SourceX/controls/plctrls.cpp. +extern void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY); +extern void plrctrls_after_check_curs_move(); extern void plrctrls_every_frame(); extern void plrctrls_after_game_logic(); -void initKeymapActions(); - -[[noreturn]] static void PrintHelpAndExit() -{ - printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "Options:\n")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-h, --help", _("Print this message and exit")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--version", _("Print the version and exit")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--data-dir", _("Specify the folder of diabdat.mpq")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--save-dir", _("Specify the folder of save files")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--config-dir", _("Specify the location of diablo.ini")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--ttf-dir", _("Specify the location of the .ttf font")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--ttf-name", _("Specify the name of a custom .ttf font")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-n", _("Skip startup videos")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-f", _("Display frames per second")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-x", _("Run in windowed mode")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--verbose", _("Enable verbose logging")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--spawn", _("Force spawn mode even if diabdat.mpq is found")); - printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "\nHellfire options:\n")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--diablo", _("Force diablo mode even if hellfire.mpq is found")); - printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--nestart", _("Use alternate nest palette")); -#ifdef _DEBUG - printInConsole("\nDebug options:\n"); - printInConsole(" %-20s %-30s\n", "-w", "Enable cheats"); - printInConsole(" %-20s %-30s\n", "-$", "Enable god mode"); - printInConsole(" %-20s %-30s\n", "-^", "Enable god mode and debug tools"); - printInConsole(" %-20s %-30s\n", "-v", "Highlight visibility"); - printInConsole(" %-20s %-30s\n", "-i", "Ignore network timeout"); - printInConsole(" %-20s %-30s\n", "-j <##>", "Mausoleum warps to given level"); - printInConsole(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type"); - printInConsole(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed"); - printInConsole(" %-20s %-30s\n", "-q <#>", "Force a certain quest"); - printInConsole(" %-20s %-30s\n", "-r <##########>", "Set map seed"); - printInConsole(" %-20s %-30s\n", "-t <##>", "Set current quest level"); -#endif - printInConsole("%s", _("\nReport bugs at https://github.com/diasurgical/devilutionX/\n")); - diablo_quit(0); -} - -static void DiabloParseFlags(int argc, char **argv) -{ - for (int i = 1; i < argc; i++) { - if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) { - PrintHelpAndExit(); - } else if (strcasecmp("--version", argv[i]) == 0) { - printInConsole("%s v%s\n", PROJECT_NAME, PROJECT_VERSION); - diablo_quit(0); - } else if (strcasecmp("--data-dir", argv[i]) == 0) { - paths::SetBasePath(argv[++i]); - } else if (strcasecmp("--save-dir", argv[i]) == 0) { - paths::SetPrefPath(argv[++i]); - } else if (strcasecmp("--config-dir", argv[i]) == 0) { - paths::SetConfigPath(argv[++i]); - } else if (strcasecmp("--lang-dir", argv[i]) == 0) { - paths::SetLangPath(argv[++i]); - } else if (strcasecmp("--ttf-dir", argv[i]) == 0) { - paths::SetTtfPath(argv[++i]); - } else if (strcasecmp("--ttf-name", argv[i]) == 0) { - paths::SetTtfName(argv[++i]); - } else if (strcasecmp("-n", argv[i]) == 0) { - gbShowIntro = false; - } else if (strcasecmp("-f", argv[i]) == 0) { - EnableFrameCount(); - } else if (strcasecmp("-x", argv[i]) == 0) { - gbForceWindowed = true; - } else if (strcasecmp("--spawn", argv[i]) == 0) { - forceSpawn = true; - } else if (strcasecmp("--diablo", argv[i]) == 0) { - forceDiablo = true; - } else if (strcasecmp("--nestart", argv[i]) == 0) { - gbNestArt = true; - } else if (strcasecmp("--vanilla", argv[i]) == 0) { - gbVanilla = true; - } else if (strcasecmp("--verbose", argv[i]) == 0) { - SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); -#ifdef _DEBUG - } else if (strcasecmp("-^", argv[i]) == 0) { - debug_mode_key_inverted_v = true; - } else if (strcasecmp("-$", argv[i]) == 0) { - debug_mode_dollar_sign = true; - } else if (strcasecmp("-i", argv[i]) == 0) { - debug_mode_key_i = true; - } else if (strcasecmp("-j", argv[i]) == 0) { - debug_mode_key_j = SDL_atoi(argv[++i]); - } else if (strcasecmp("-l", argv[i]) == 0) { - setlevel = false; - leveldebug = true; - leveltype = (dungeon_type)SDL_atoi(argv[++i]); - currlevel = SDL_atoi(argv[++i]); - Players[0].plrlevel = currlevel; - } else if (strcasecmp("-m", argv[i]) == 0) { - monstdebug = true; - DebugMonsters[debugmonsttypes++] = (_monster_id)SDL_atoi(argv[++i]); - } else if (strcasecmp("-q", argv[i]) == 0) { - questdebug = SDL_atoi(argv[++i]); - } else if (strcasecmp("-r", argv[i]) == 0) { - setseed = SDL_atoi(argv[++i]); - } else if (strcasecmp("-s", argv[i]) == 0) { - debug_mode_key_s = true; - } else if (strcasecmp("-t", argv[i]) == 0) { - leveldebug = true; - setlevel = true; - setlvlnum = (_setlevels)SDL_atoi(argv[++i]); - } else if (strcasecmp("-v", argv[i]) == 0) { - visiondebug = true; - } else if (strcasecmp("-w", argv[i]) == 0) { - debug_mode_key_w = true; -#endif - } else { - printInConsole("%s", fmt::format(_("unrecognized option '{:s}'\n"), argv[i]).c_str()); - PrintHelpAndExit(); - } - } -} +namespace { -void FreeGameMem() -{ - music_stop(); +char gszVersionNumber[64] = "internal version unknown"; - pDungeonCels = nullptr; - pMegaTiles = nullptr; - pLevelPieces = nullptr; - pSpecialCels = std::nullopt; +// Used for debugging level generation +uint32_t glEndSeed[NUMLEVELS]; +uint32_t glMid1Seed[NUMLEVELS]; +uint32_t glMid2Seed[NUMLEVELS]; +uint32_t glMid3Seed[NUMLEVELS]; - FreeMissiles(); - FreeMonsters(); - FreeObjectGFX(); - FreeMonsterSnd(); - FreeTownerGFX(); -} +bool gbGameLoopStartup; +int setseed; +bool forceSpawn; +bool forceDiablo; +int sgnTimeoutCurs; +bool gbShowIntro = true; +int arrowdebug = 0; +/** To know if these things have been done when we get to the diablo_deinit() function */ +bool was_archives_init = false; +/** To know if surfaces have been initialized or not */ +bool was_window_init = false; +bool was_ui_init = false; +bool was_snd_init = false; static void StartGame(interface_mode uMsg) { @@ -326,11 +199,6 @@ static void FreeGame() FreeGameMem(); } -// Controller support: Actions to run after updating the cursor state. -// Defined in SourceX/controls/plctrls.cpp. -extern void finish_simulated_mouse_clicks(int currentMouseX, int currentMouseY); -extern void plrctrls_after_check_curs_move(); - static bool ProcessInput() { if (PauseMode == 2) { @@ -428,61 +296,127 @@ static void RunGameLoop(interface_mode uMsg) } } -bool StartGame(bool bNewGame, bool bSinglePlayer) +[[noreturn]] static void PrintHelpAndExit() { - gbSelectProvider = true; - - do { - gbLoadGame = false; - - if (!NetInit(bSinglePlayer)) { - gbRunGameResult = true; - break; - } - - // Save 2.8 MiB of RAM by freeing all main menu resources - // before starting the game. - UiDestroy(); - - gbSelectProvider = false; - - if (bNewGame || !gbValidSaveFile) { - InitLevels(); - InitQuests(); - InitPortals(); - InitDungMsgs(Players[MyPlayerId]); - } - interface_mode uMsg = WM_DIABNEWGAME; - if (gbValidSaveFile && gbLoadGame) { - uMsg = WM_DIABLOADGAME; - } - RunGameLoop(uMsg); - NetClose(); - - // If the player left the game into the main menu, - // initialize main menu resources. - if (gbRunGameResult) - UiInitialize(); - } while (gbRunGameResult); - - SNetDestroy(); - return gbRunGameResult; + printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "Options:\n")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-h, --help", _("Print this message and exit")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--version", _("Print the version and exit")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--data-dir", _("Specify the folder of diabdat.mpq")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--save-dir", _("Specify the folder of save files")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--config-dir", _("Specify the location of diablo.ini")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--ttf-dir", _("Specify the location of the .ttf font")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--ttf-name", _("Specify the name of a custom .ttf font")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-n", _("Skip startup videos")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-f", _("Display frames per second")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "-x", _("Run in windowed mode")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--verbose", _("Enable verbose logging")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--spawn", _("Force spawn mode even if diabdat.mpq is found")); + printInConsole("%s", _(/* TRANSLATORS: Commandline Option */ "\nHellfire options:\n")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--diablo", _("Force diablo mode even if hellfire.mpq is found")); + printInConsole(" %-20s %-30s\n", /* TRANSLATORS: Commandline Option */ "--nestart", _("Use alternate nest palette")); +#ifdef _DEBUG + printInConsole("\nDebug options:\n"); + printInConsole(" %-20s %-30s\n", "-w", "Enable cheats"); + printInConsole(" %-20s %-30s\n", "-$", "Enable god mode"); + printInConsole(" %-20s %-30s\n", "-^", "Enable god mode and debug tools"); + printInConsole(" %-20s %-30s\n", "-v", "Highlight visibility"); + printInConsole(" %-20s %-30s\n", "-i", "Ignore network timeout"); + printInConsole(" %-20s %-30s\n", "-j <##>", "Mausoleum warps to given level"); + printInConsole(" %-20s %-30s\n", "-l <##> <##>", "Start in level as type"); + printInConsole(" %-20s %-30s\n", "-m <##>", "Add debug monster, up to 10 allowed"); + printInConsole(" %-20s %-30s\n", "-q <#>", "Force a certain quest"); + printInConsole(" %-20s %-30s\n", "-r <##########>", "Set map seed"); + printInConsole(" %-20s %-30s\n", "-t <##>", "Set current quest level"); +#endif + printInConsole("%s", _("\nReport bugs at https://github.com/diasurgical/devilutionX/\n")); + diablo_quit(0); } -static void DiabloInitScreen() +static void DiabloParseFlags(int argc, char **argv) { - MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 }; - if (!sgbControllerActive) - SetCursorPos(MousePosition.x, MousePosition.y); - ScrollInfo.tile = { 0, 0 }; - ScrollInfo.offset = { 0, 0 }; - ScrollInfo._sdir = SDIR_NONE; - - ClrDiabloMsg(); -} + for (int i = 1; i < argc; i++) { + if (strcasecmp("-h", argv[i]) == 0 || strcasecmp("--help", argv[i]) == 0) { + PrintHelpAndExit(); + } else if (strcasecmp("--version", argv[i]) == 0) { + printInConsole("%s v%s\n", PROJECT_NAME, PROJECT_VERSION); + diablo_quit(0); + } else if (strcasecmp("--data-dir", argv[i]) == 0) { + paths::SetBasePath(argv[++i]); + } else if (strcasecmp("--save-dir", argv[i]) == 0) { + paths::SetPrefPath(argv[++i]); + } else if (strcasecmp("--config-dir", argv[i]) == 0) { + paths::SetConfigPath(argv[++i]); + } else if (strcasecmp("--lang-dir", argv[i]) == 0) { + paths::SetLangPath(argv[++i]); + } else if (strcasecmp("--ttf-dir", argv[i]) == 0) { + paths::SetTtfPath(argv[++i]); + } else if (strcasecmp("--ttf-name", argv[i]) == 0) { + paths::SetTtfName(argv[++i]); + } else if (strcasecmp("-n", argv[i]) == 0) { + gbShowIntro = false; + } else if (strcasecmp("-f", argv[i]) == 0) { + EnableFrameCount(); + } else if (strcasecmp("-x", argv[i]) == 0) { + gbForceWindowed = true; + } else if (strcasecmp("--spawn", argv[i]) == 0) { + forceSpawn = true; + } else if (strcasecmp("--diablo", argv[i]) == 0) { + forceDiablo = true; + } else if (strcasecmp("--nestart", argv[i]) == 0) { + gbNestArt = true; + } else if (strcasecmp("--vanilla", argv[i]) == 0) { + gbVanilla = true; + } else if (strcasecmp("--verbose", argv[i]) == 0) { + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); +#ifdef _DEBUG + } else if (strcasecmp("-^", argv[i]) == 0) { + debug_mode_key_inverted_v = true; + } else if (strcasecmp("-$", argv[i]) == 0) { + debug_mode_dollar_sign = true; + } else if (strcasecmp("-i", argv[i]) == 0) { + debug_mode_key_i = true; + } else if (strcasecmp("-j", argv[i]) == 0) { + debug_mode_key_j = SDL_atoi(argv[++i]); + } else if (strcasecmp("-l", argv[i]) == 0) { + setlevel = false; + leveldebug = true; + leveltype = (dungeon_type)SDL_atoi(argv[++i]); + currlevel = SDL_atoi(argv[++i]); + Players[0].plrlevel = currlevel; + } else if (strcasecmp("-m", argv[i]) == 0) { + monstdebug = true; + DebugMonsters[debugmonsttypes++] = (_monster_id)SDL_atoi(argv[++i]); + } else if (strcasecmp("-q", argv[i]) == 0) { + questdebug = SDL_atoi(argv[++i]); + } else if (strcasecmp("-r", argv[i]) == 0) { + setseed = SDL_atoi(argv[++i]); + } else if (strcasecmp("-t", argv[i]) == 0) { + leveldebug = true; + setlevel = true; + setlvlnum = (_setlevels)SDL_atoi(argv[++i]); + } else if (strcasecmp("-v", argv[i]) == 0) { + visiondebug = true; + } else if (strcasecmp("-w", argv[i]) == 0) { + debug_mode_key_w = true; +#endif + } else { + printInConsole("%s", fmt::format(_("unrecognized option '{:s}'\n"), argv[i]).c_str()); + PrintHelpAndExit(); + } + } +} -char gszVersionNumber[64] = "internal version unknown"; -char gszProductName[64] = "DevilutionX vUnknown"; +static void DiabloInitScreen() +{ + MousePosition = { gnScreenWidth / 2, gnScreenHeight / 2 }; + if (!sgbControllerActive) + SetCursorPos(MousePosition.x, MousePosition.y); + ScrollInfo.tile = { 0, 0 }; + ScrollInfo.offset = { 0, 0 }; + ScrollInfo._sdir = SDIR_NONE; + + ClrDiabloMsg(); +} static void SetApplicationVersions() { @@ -584,29 +518,6 @@ static void DiabloDeinit() SDL_Quit(); } -void diablo_quit(int exitStatus) -{ - DiabloDeinit(); - exit(exitStatus); -} - -int DiabloMain(int argc, char **argv) -{ -#ifdef _DEBUG - SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); -#endif - - DiabloParseFlags(argc, argv); - initKeymapActions(); - LoadOptions(); - DiabloInit(); - DiabloSplash(); - mainmenu_loop(); - DiabloDeinit(); - - return 0; -} - static bool LeftMouseCmd(bool bShift) { bool bNear; @@ -663,75 +574,6 @@ static bool LeftMouseCmd(bool bShift) return false; } -bool TryIconCurs() -{ - if (pcurs == CURSOR_RESURRECT) { - NetSendCmdParam1(true, CMD_RESURRECT, pcursplr); - return true; - } - - if (pcurs == CURSOR_HEALOTHER) { - NetSendCmdParam1(true, CMD_HEALOTHER, pcursplr); - return true; - } - - if (pcurs == CURSOR_TELEKINESIS) { - DoTelekinesis(); - return true; - } - - if (pcurs == CURSOR_IDENTIFY) { - if (pcursinvitem != -1) - CheckIdentify(MyPlayerId, pcursinvitem); - else - NewCursor(CURSOR_HAND); - return true; - } - - if (pcurs == CURSOR_REPAIR) { - if (pcursinvitem != -1) - DoRepair(MyPlayerId, pcursinvitem); - else - NewCursor(CURSOR_HAND); - return true; - } - - if (pcurs == CURSOR_RECHARGE) { - if (pcursinvitem != -1) - DoRecharge(MyPlayerId, pcursinvitem); - else - NewCursor(CURSOR_HAND); - return true; - } - - if (pcurs == CURSOR_OIL) { - if (pcursinvitem != -1) - DoOil(MyPlayerId, pcursinvitem); - else - NewCursor(CURSOR_HAND); - return true; - } - - if (pcurs == CURSOR_TELEPORT) { - auto &myPlayer = Players[MyPlayerId]; - if (pcursmonst != -1) - NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); - else if (pcursplr != -1) - NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); - else - NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); - NewCursor(CURSOR_HAND); - return true; - } - - if (pcurs == CURSOR_DISARM && pcursobj == -1) { - NewCursor(CURSOR_HAND); - return true; - } - - return false; -} - static bool LeftMouseDown(int wParam) { if (gmenu_left_mouse(true)) @@ -849,20 +691,6 @@ static void RightMouseDown() } } -void diablo_pause_game() -{ - if (!gbIsMultiplayer) { - if (PauseMode != 0) { - PauseMode = 0; - } else { - PauseMode = 2; - sound_stop(); - track_repeat_walk(false); - } - force_redraw = 255; - } -} - static void DiabloHotkeyMsg(DWORD dwMsg) { if (!gbIsMultiplayer) { @@ -907,59 +735,6 @@ static void ClosePanels() QuestLogIsOpen = false; } -bool PressEscKey() -{ - bool rv = false; - - if (DoomFlag) { - doom_close(); - rv = true; - } - - if (HelpFlag) { - HelpFlag = false; - rv = true; - } - - if (qtextflag) { - qtextflag = false; - stream_stop(); - rv = true; - } - - if (stextflag != STORE_NONE) { - StoreESC(); - rv = true; - } - - if (msgflag != EMSG_NONE) { - msgdelay = 0; - rv = true; - } - - if (talkflag) { - control_reset_talk(); - rv = true; - } - - if (dropGoldFlag) { - control_drop_gold(DVL_VK_ESCAPE); - rv = true; - } - - if (spselflag) { - spselflag = false; - rv = true; - } - - if (invflag || chrflag || sbookflag || QuestLogIsOpen) { - ClosePanels(); - rv = true; - } - - return rv; -} - static void PressKey(int vkey) { if (gmenu_presskeys(vkey) || control_presskeys(vkey)) { @@ -1201,136 +976,7 @@ static void GetMousePos(int32_t lParam) MousePosition = { (std::int16_t)(lParam & 0xffff), (std::int16_t)((lParam >> 16) & 0xffff) }; } -void DisableInputWndProc(uint32_t uMsg, int32_t /*wParam*/, int32_t lParam) -{ - switch (uMsg) { - case DVL_WM_KEYDOWN: - case DVL_WM_KEYUP: - case DVL_WM_CHAR: - case DVL_WM_SYSKEYDOWN: - case DVL_WM_SYSCOMMAND: - return; - case DVL_WM_MOUSEMOVE: - GetMousePos(lParam); - return; - case DVL_WM_LBUTTONDOWN: - if (sgbMouseDown != CLICK_NONE) - return; - sgbMouseDown = CLICK_LEFT; - return; - case DVL_WM_LBUTTONUP: - if (sgbMouseDown != CLICK_LEFT) - return; - sgbMouseDown = CLICK_NONE; - return; - case DVL_WM_RBUTTONDOWN: - if (sgbMouseDown != CLICK_NONE) - return; - sgbMouseDown = CLICK_RIGHT; - return; - case DVL_WM_RBUTTONUP: - if (sgbMouseDown != CLICK_RIGHT) - return; - sgbMouseDown = CLICK_NONE; - return; - case DVL_WM_CAPTURECHANGED: - sgbMouseDown = CLICK_NONE; - return; - } - - MainWndProc(uMsg); -} - -void GM_Game(uint32_t uMsg, int32_t wParam, int32_t lParam) -{ - switch (uMsg) { - case DVL_WM_KEYDOWN: - PressKey(wParam); - return; - case DVL_WM_KEYUP: - ReleaseKey(wParam); - return; - case DVL_WM_CHAR: - PressChar(wParam); - return; - case DVL_WM_SYSKEYDOWN: - if (PressSysKey(wParam)) - return; - break; - case DVL_WM_SYSCOMMAND: - if (wParam == DVL_SC_CLOSE) { - gbRunGame = false; - gbRunGameResult = false; - return; - } - break; - case DVL_WM_MOUSEMOVE: - GetMousePos(lParam); - gmenu_on_mouse_move(); - return; - case DVL_WM_LBUTTONDOWN: - GetMousePos(lParam); - if (sgbMouseDown == CLICK_NONE) { - sgbMouseDown = CLICK_LEFT; - track_repeat_walk(LeftMouseDown(wParam)); - } - return; - case DVL_WM_LBUTTONUP: - GetMousePos(lParam); - if (sgbMouseDown == CLICK_LEFT) { - sgbMouseDown = CLICK_NONE; - LeftMouseUp(wParam); - track_repeat_walk(false); - } - return; - case DVL_WM_RBUTTONDOWN: - GetMousePos(lParam); - if (sgbMouseDown == CLICK_NONE) { - sgbMouseDown = CLICK_RIGHT; - RightMouseDown(); - } - return; - case DVL_WM_RBUTTONUP: - GetMousePos(lParam); - if (sgbMouseDown == CLICK_RIGHT) { - sgbMouseDown = CLICK_NONE; - } - return; - case DVL_WM_CAPTURECHANGED: - sgbMouseDown = CLICK_NONE; - track_repeat_walk(false); - break; - case WM_DIABNEXTLVL: - case WM_DIABPREVLVL: - case WM_DIABRTNLVL: - case WM_DIABSETLVL: - case WM_DIABWARPLVL: - case WM_DIABTOWNWARP: - case WM_DIABTWARPUP: - case WM_DIABRETOWN: - if (gbIsMultiplayer) - pfile_write_hero(); - nthread_ignore_mutex(true); - PaletteFadeOut(8); - sound_stop(); - music_stop(); - track_repeat_walk(false); - sgbMouseDown = CLICK_NONE; - ShowProgress((interface_mode)uMsg); - force_redraw = 255; - DrawAndBlit(); - LoadPWaterPalette(); - if (gbRunGame) - PaletteFadeIn(8); - nthread_ignore_mutex(false); - gbGameLoopStartup = true; - return; - } - - MainWndProc(uMsg); -} - -void LoadLvlGFX() +void LoadLvlGFX() { assert(pDungeonCels == nullptr); constexpr int SpecialCelWidth = 64; @@ -1466,498 +1112,219 @@ static void UpdateMonsterLights() } } -void LoadGameLevel(bool firstflag, lvl_entry lvldir) +static void GameLogic() { - if (setseed != 0) - glSeedTbl[currlevel] = setseed; - - music_stop(); - if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { - NewCursor(CURSOR_HAND); + if (!ProcessInput()) { + return; } - SetRndSeed(glSeedTbl[currlevel]); - IncProgress(); - MakeLightTable(); - LoadLvlGFX(); - IncProgress(); - - if (firstflag) { - InitInv(); - InitQuestText(); - InitStores(); - InitAutomapOnce(); - InitHelp(); - InitText(); + if (gbProcessPlayers) { + gGameLogicStep = GameLogicStep::ProcessPlayers; + ProcessPlayers(); } - - SetRndSeed(glSeedTbl[currlevel]); - - if (leveltype == DTYPE_TOWN) - SetupTownStores(); - - IncProgress(); - InitAutomap(); - - if (leveltype != DTYPE_TOWN && lvldir != ENTRY_LOAD) { - InitLighting(); - InitVision(); + if (leveltype != DTYPE_TOWN) { + gGameLogicStep = GameLogicStep::ProcessMonsters; + ProcessMonsters(); + gGameLogicStep = GameLogicStep::ProcessObjects; + ProcessObjects(); + gGameLogicStep = GameLogicStep::ProcessMissiles; + ProcessMissiles(); + gGameLogicStep = GameLogicStep::ProcessItems; + ProcessItems(); + ProcessLightList(); + ProcessVisionList(); + } else { + gGameLogicStep = GameLogicStep::ProcessTowners; + ProcessTowners(); + gGameLogicStep = GameLogicStep::ProcessItemsTown; + ProcessItems(); + gGameLogicStep = GameLogicStep::ProcessMissilesTown; + ProcessMissiles(); } + gGameLogicStep = GameLogicStep::None; - InitLevelMonsters(); - IncProgress(); +#ifdef _DEBUG + if (debug_mode_key_inverted_v && GetAsyncKeyState(DVL_VK_SHIFT)) { + ScrollView(); + } +#endif - auto &myPlayer = Players[MyPlayerId]; + sound_update(); + ClearPlrMsg(); + CheckTriggers(); + CheckQuests(); + force_redraw |= 1; + pfile_update(false); - if (!setlevel) { - CreateLevel(lvldir); - IncProgress(); - FillSolidBlockTbls(); - SetRndSeed(glSeedTbl[currlevel]); + plrctrls_after_game_logic(); +} - if (leveltype != DTYPE_TOWN) { - GetLevelMTypes(); - InitThemes(); - LoadAllGFX(); - } else { - IncProgress(); - IncProgress(); - InitMissileGFX(); - IncProgress(); - IncProgress(); +static void TimeoutCursor(bool bTimeout) +{ + if (bTimeout) { + if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) { + sgnTimeoutCurs = pcurs; + multi_net_ping(); + ClearPanel(); + AddPanelString(_("-- Network timeout --")); + AddPanelString(_("-- Waiting for players --")); + NewCursor(CURSOR_HOURGLASS); + force_redraw = 255; } + scrollrt_draw_game_screen(); + } else if (sgnTimeoutCurs != CURSOR_NONE) { + NewCursor(sgnTimeoutCurs); + sgnTimeoutCurs = CURSOR_NONE; + ClearPanel(); + force_redraw = 255; + } +} - IncProgress(); +void helpKeyPressed() +{ + if (HelpFlag) { + HelpFlag = false; + } else if (stextflag != STORE_NONE) { + ClearPanel(); + AddPanelString(_("No help available")); /// BUGFIX: message isn't displayed + AddPanelString(_("while in stores")); + track_repeat_walk(false); + } else { + invflag = false; + chrflag = false; + sbookflag = false; + spselflag = false; + if (qtextflag && leveltype == DTYPE_TOWN) { + qtextflag = false; + stream_stop(); + } + QuestLogIsOpen = false; + AutomapActive = false; + msgdelay = 0; + gamemenu_off(); + DisplayHelp(); + doom_close(); + } +} - if (lvldir == ENTRY_RTNLVL) - GetReturnLvlPos(); - if (lvldir == ENTRY_WARPLVL) - GetPortalLvlPos(); - - IncProgress(); - - for (int i = 0; i < MAX_PLRS; i++) { - auto &player = Players[i]; - if (player.plractive && currlevel == player.plrlevel) { - InitPlayerGFX(player); - if (lvldir != ENTRY_LOAD) - InitPlayer(i, firstflag); - } - } - - PlayDungMsgs(); - InitMultiView(); - IncProgress(); - - bool visited = false; - int players = gbIsMultiplayer ? MAX_PLRS : 1; - for (int i = 0; i < players; i++) { - auto &player = Players[i]; - if (player.plractive) - visited = visited || player._pLvlVisited[currlevel]; - } - - SetRndSeed(glSeedTbl[currlevel]); - - if (leveltype != DTYPE_TOWN) { - if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pLvlVisited[currlevel] || gbIsMultiplayer) { - HoldThemeRooms(); - glMid1Seed[currlevel] = GetLCGEngineState(); - InitMonsters(); - glMid2Seed[currlevel] = GetLCGEngineState(); - IncProgress(); - InitObjects(); - InitItems(); - if (currlevel < 17) - CreateThemeRooms(); - IncProgress(); - glMid3Seed[currlevel] = GetLCGEngineState(); - InitMissiles(); - InitDead(); - glEndSeed[currlevel] = GetLCGEngineState(); - - if (gbIsMultiplayer) - DeltaLoadLevel(); +#ifdef _DEBUG +void itemInfoKeyPressed() +{ + if (pcursitem != -1) { + sprintf( + tempstr, + "IDX = %i : Seed = %i : CF = %i", + Items[pcursitem].IDidx, + Items[pcursitem]._iSeed, + Items[pcursitem]._iCreateInfo); + NetSendCmdString(1 << MyPlayerId, tempstr); + } + sprintf(tempstr, "Numitems : %i", ActiveItemCount); + NetSendCmdString(1 << MyPlayerId, tempstr); +} +#endif - IncProgress(); - SavePreLighting(); - } else { - HoldThemeRooms(); - InitMonsters(); - InitMissiles(); - InitDead(); - IncProgress(); - LoadLevel(); - IncProgress(); +void inventoryKeyPressed() +{ + if (stextflag != STORE_NONE) + return; + invflag = !invflag; + if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { + if (!invflag) { // We closed the invetory + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } - } else { - for (int i = 0; i < MAXDUNX; i++) { // NOLINT(modernize-loop-convert) - for (int j = 0; j < MAXDUNY; j++) { - dFlags[i][j] |= BFLAG_LIT; - } + } else if (!sbookflag) { // We opened the invetory + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); } - - InitTowners(); - InitItems(); - InitMissiles(); - IncProgress(); - - if (!firstflag && lvldir != ENTRY_LOAD && myPlayer._pLvlVisited[currlevel] && !gbIsMultiplayer) - LoadLevel(); - if (gbIsMultiplayer) - DeltaLoadLevel(); - - IncProgress(); } - if (!gbIsMultiplayer) - ResyncQuests(); - else - ResyncMPQuests(); - } else { - LoadSetMap(); - IncProgress(); - GetLevelMTypes(); - IncProgress(); - InitMonsters(); - IncProgress(); - InitMissileGFX(); - IncProgress(); - InitDead(); - IncProgress(); - FillSolidBlockTbls(); - IncProgress(); - - if (lvldir == ENTRY_WARPLVL) - GetPortalLvlPos(); - IncProgress(); + } + sbookflag = false; +} - for (int i = 0; i < MAX_PLRS; i++) { - auto &player = Players[i]; - if (player.plractive && currlevel == player.plrlevel) { - InitPlayerGFX(player); - if (lvldir != ENTRY_LOAD) - InitPlayer(i, firstflag); +void characterSheetKeyPressed() +{ + if (stextflag != STORE_NONE) + return; + chrflag = !chrflag; + if (!invflag && !sbookflag && CanPanelsCoverView()) { + if (!chrflag) { // We closed the character sheet + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); + } + } else if (!QuestLogIsOpen) { // We opened the character sheet + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } - IncProgress(); - - InitMultiView(); - IncProgress(); - - if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pSLvlVisited[setlvlnum]) { - InitItems(); - SavePreLighting(); - } else { - LoadLevel(); - } - - InitMissiles(); - IncProgress(); } + QuestLogIsOpen = false; +} - SyncPortals(); - - for (int i = 0; i < MAX_PLRS; i++) { - auto &player = Players[i]; - if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == MyPlayerId)) { - if (player._pHitPoints > 0) { - if (!gbIsMultiplayer) - dPlayer[player.position.tile.x][player.position.tile.y] = i + 1; - else - SyncInitPlrPos(i); - } else { - dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER; +void questLogKeyPressed() +{ + if (stextflag != STORE_NONE) + return; + if (!QuestLogIsOpen) { + StartQuestlog(); + } else { + QuestLogIsOpen = false; + } + if (!invflag && !sbookflag && CanPanelsCoverView()) { + if (!QuestLogIsOpen) { // We closed the quest log + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); + } + } else if (!chrflag) { // We opened the character quest log + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); } } } + chrflag = false; +} - SetDungeonMicros(); - - InitLightMax(); - IncProgress(); - IncProgress(); - - if (firstflag) { - InitControlPan(); - } - IncProgress(); - UpdateMonsterLights(); - if (leveltype != DTYPE_TOWN) { - ProcessLightList(); - ProcessVisionList(); +void displaySpellsKeyPressed() +{ + if (stextflag != STORE_NONE) + return; + chrflag = false; + QuestLogIsOpen = false; + invflag = false; + sbookflag = false; + if (!spselflag) { + DoSpeedBook(); + } else { + spselflag = false; } + track_repeat_walk(false); +} - if (currlevel >= 21) { - if (currlevel == 21) { - CornerstoneLoad(CornerStone.position); - } - if (Quests[Q_NAKRUL]._qactive == QUEST_DONE && currlevel == 24) { - SyncNakrulRoom(); +void spellBookKeyPressed() +{ + if (stextflag != STORE_NONE) + return; + sbookflag = !sbookflag; + if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { + if (!sbookflag) { // We closed the invetory + if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x + 160, MousePosition.y); + } + } else if (!invflag) { // We opened the invetory + if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { + SetCursorPos(MousePosition.x - 160, MousePosition.y); + } } } + invflag = false; +} - if (currlevel >= 17) - music_start(currlevel > 20 ? TMUSIC_L5 : TMUSIC_L6); - else - music_start(leveltype); - - while (!IncProgress()) - ; - - if (!gbIsSpawn && setlevel && setlvlnum == SL_SKELKING && Quests[Q_SKELKING]._qactive == QUEST_ACTIVE) - PlaySFX(USFX_SKING1); +bool isPlayerDead() +{ + return Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead; } -static void GameLogic() -{ - if (!ProcessInput()) { - return; - } - if (gbProcessPlayers) { - gGameLogicStep = GameLogicStep::ProcessPlayers; - ProcessPlayers(); - } - if (leveltype != DTYPE_TOWN) { - gGameLogicStep = GameLogicStep::ProcessMonsters; - ProcessMonsters(); - gGameLogicStep = GameLogicStep::ProcessObjects; - ProcessObjects(); - gGameLogicStep = GameLogicStep::ProcessMissiles; - ProcessMissiles(); - gGameLogicStep = GameLogicStep::ProcessItems; - ProcessItems(); - ProcessLightList(); - ProcessVisionList(); - } else { - gGameLogicStep = GameLogicStep::ProcessTowners; - ProcessTowners(); - gGameLogicStep = GameLogicStep::ProcessItemsTown; - ProcessItems(); - gGameLogicStep = GameLogicStep::ProcessMissilesTown; - ProcessMissiles(); - } - gGameLogicStep = GameLogicStep::None; - -#ifdef _DEBUG - if (debug_mode_key_inverted_v && GetAsyncKeyState(DVL_VK_SHIFT)) { - ScrollView(); - } -#endif - - sound_update(); - ClearPlrMsg(); - CheckTriggers(); - CheckQuests(); - force_redraw |= 1; - pfile_update(false); - - plrctrls_after_game_logic(); -} - -static void TimeoutCursor(bool bTimeout) -{ - if (bTimeout) { - if (sgnTimeoutCurs == CURSOR_NONE && sgbMouseDown == CLICK_NONE) { - sgnTimeoutCurs = pcurs; - multi_net_ping(); - ClearPanel(); - AddPanelString(_("-- Network timeout --")); - AddPanelString(_("-- Waiting for players --")); - NewCursor(CURSOR_HOURGLASS); - force_redraw = 255; - } - scrollrt_draw_game_screen(); - } else if (sgnTimeoutCurs != CURSOR_NONE) { - NewCursor(sgnTimeoutCurs); - sgnTimeoutCurs = CURSOR_NONE; - ClearPanel(); - force_redraw = 255; - } -} - -/** - * @param bStartup Process additional ticks before returning - */ -void game_loop(bool bStartup) -{ - uint16_t wait = bStartup ? sgGameInitInfo.nTickRate * 3 : 3; - - for (unsigned i = 0; i < wait; i++) { - if (!multi_handle_delta()) { - TimeoutCursor(true); - break; - } - TimeoutCursor(false); - GameLogic(); - - if (!gbRunGame || !gbIsMultiplayer || !nthread_has_500ms_passed()) - break; - } -} - -void diablo_color_cyc_logic() -{ - if (!sgOptions.Graphics.bColorCycling) - return; - - if (leveltype == DTYPE_HELL) { - lighting_color_cycling(); - } else if (currlevel >= 21) { - palette_update_crypt(); - } else if (currlevel >= 17) { - palette_update_hive(); - } else if (setlevel && setlvlnum == Quests[Q_PWATER]._qslvl) { - UpdatePWaterPalette(); - } else if (leveltype == DTYPE_CAVES) { - palette_update_caves(); - } -} - -void helpKeyPressed() -{ - if (HelpFlag) { - HelpFlag = false; - } else if (stextflag != STORE_NONE) { - ClearPanel(); - AddPanelString(_("No help available")); /// BUGFIX: message isn't displayed - AddPanelString(_("while in stores")); - track_repeat_walk(false); - } else { - invflag = false; - chrflag = false; - sbookflag = false; - spselflag = false; - if (qtextflag && leveltype == DTYPE_TOWN) { - qtextflag = false; - stream_stop(); - } - QuestLogIsOpen = false; - AutomapActive = false; - msgdelay = 0; - gamemenu_off(); - DisplayHelp(); - doom_close(); - } -} - -#ifdef _DEBUG -void itemInfoKeyPressed() -{ - if (pcursitem != -1) { - sprintf( - tempstr, - "IDX = %i : Seed = %i : CF = %i", - Items[pcursitem].IDidx, - Items[pcursitem]._iSeed, - Items[pcursitem]._iCreateInfo); - NetSendCmdString(1 << MyPlayerId, tempstr); - } - sprintf(tempstr, "Numitems : %i", ActiveItemCount); - NetSendCmdString(1 << MyPlayerId, tempstr); -} -#endif - -void inventoryKeyPressed() -{ - if (stextflag != STORE_NONE) - return; - invflag = !invflag; - if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { - if (!invflag) { // We closed the invetory - if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); - } - } else if (!sbookflag) { // We opened the invetory - if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); - } - } - } - sbookflag = false; -} - -void characterSheetKeyPressed() -{ - if (stextflag != STORE_NONE) - return; - chrflag = !chrflag; - if (!invflag && !sbookflag && CanPanelsCoverView()) { - if (!chrflag) { // We closed the character sheet - if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); - } - } else if (!QuestLogIsOpen) { // We opened the character sheet - if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); - } - } - } - QuestLogIsOpen = false; -} - -void questLogKeyPressed() -{ - if (stextflag != STORE_NONE) - return; - if (!QuestLogIsOpen) { - StartQuestlog(); - } else { - QuestLogIsOpen = false; - } - if (!invflag && !sbookflag && CanPanelsCoverView()) { - if (!QuestLogIsOpen) { // We closed the quest log - if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); - } - } else if (!chrflag) { // We opened the character quest log - if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); - } - } - } - chrflag = false; -} - -void displaySpellsKeyPressed() -{ - if (stextflag != STORE_NONE) - return; - chrflag = false; - QuestLogIsOpen = false; - invflag = false; - sbookflag = false; - if (!spselflag) { - DoSpeedBook(); - } else { - spselflag = false; - } - track_repeat_walk(false); -} - -void spellBookKeyPressed() -{ - if (stextflag != STORE_NONE) - return; - sbookflag = !sbookflag; - if (!chrflag && !QuestLogIsOpen && CanPanelsCoverView()) { - if (!sbookflag) { // We closed the invetory - if (MousePosition.x < 480 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x + 160, MousePosition.y); - } - } else if (!invflag) { // We opened the invetory - if (MousePosition.x > 160 && MousePosition.y < PANEL_TOP) { - SetCursorPos(MousePosition.x - 160, MousePosition.y); - } - } - } - invflag = false; -} - -bool isPlayerDead() -{ - return Players[MyPlayerId]._pmode == PM_DEATH || MyPlayerIsDead; -} - -void initKeymapActions() +void initKeymapActions() { keymapper.AddAction({ "Help", @@ -2120,4 +1487,630 @@ void initKeymapActions() }); } +} // namespace + +void FreeGameMem() +{ + music_stop(); + + pDungeonCels = nullptr; + pMegaTiles = nullptr; + pLevelPieces = nullptr; + pSpecialCels = std::nullopt; + + FreeMissiles(); + FreeMonsters(); + FreeObjectGFX(); + FreeMonsterSnd(); + FreeTownerGFX(); +} + +bool StartGame(bool bNewGame, bool bSinglePlayer) +{ + gbSelectProvider = true; + + do { + gbLoadGame = false; + + if (!NetInit(bSinglePlayer)) { + gbRunGameResult = true; + break; + } + + // Save 2.8 MiB of RAM by freeing all main menu resources + // before starting the game. + UiDestroy(); + + gbSelectProvider = false; + + if (bNewGame || !gbValidSaveFile) { + InitLevels(); + InitQuests(); + InitPortals(); + InitDungMsgs(Players[MyPlayerId]); + } + interface_mode uMsg = WM_DIABNEWGAME; + if (gbValidSaveFile && gbLoadGame) { + uMsg = WM_DIABLOADGAME; + } + RunGameLoop(uMsg); + NetClose(); + + // If the player left the game into the main menu, + // initialize main menu resources. + if (gbRunGameResult) + UiInitialize(); + } while (gbRunGameResult); + + SNetDestroy(); + return gbRunGameResult; +} + +void diablo_quit(int exitStatus) +{ + DiabloDeinit(); + exit(exitStatus); +} + +int DiabloMain(int argc, char **argv) +{ +#ifdef _DEBUG + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); +#endif + + DiabloParseFlags(argc, argv); + initKeymapActions(); + LoadOptions(); + DiabloInit(); + DiabloSplash(); + mainmenu_loop(); + DiabloDeinit(); + + return 0; +} + +bool TryIconCurs() +{ + if (pcurs == CURSOR_RESURRECT) { + NetSendCmdParam1(true, CMD_RESURRECT, pcursplr); + return true; + } + + if (pcurs == CURSOR_HEALOTHER) { + NetSendCmdParam1(true, CMD_HEALOTHER, pcursplr); + return true; + } + + if (pcurs == CURSOR_TELEKINESIS) { + DoTelekinesis(); + return true; + } + + if (pcurs == CURSOR_IDENTIFY) { + if (pcursinvitem != -1) + CheckIdentify(MyPlayerId, pcursinvitem); + else + NewCursor(CURSOR_HAND); + return true; + } + + if (pcurs == CURSOR_REPAIR) { + if (pcursinvitem != -1) + DoRepair(MyPlayerId, pcursinvitem); + else + NewCursor(CURSOR_HAND); + return true; + } + + if (pcurs == CURSOR_RECHARGE) { + if (pcursinvitem != -1) + DoRecharge(MyPlayerId, pcursinvitem); + else + NewCursor(CURSOR_HAND); + return true; + } + + if (pcurs == CURSOR_OIL) { + if (pcursinvitem != -1) + DoOil(MyPlayerId, pcursinvitem); + else + NewCursor(CURSOR_HAND); + return true; + } + + if (pcurs == CURSOR_TELEPORT) { + auto &myPlayer = Players[MyPlayerId]; + if (pcursmonst != -1) + NetSendCmdParam3(true, CMD_TSPELLID, pcursmonst, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); + else if (pcursplr != -1) + NetSendCmdParam3(true, CMD_TSPELLPID, pcursplr, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); + else + NetSendCmdLocParam2(true, CMD_TSPELLXY, { cursmx, cursmy }, myPlayer._pTSpell, GetSpellLevel(MyPlayerId, myPlayer._pTSpell)); + NewCursor(CURSOR_HAND); + return true; + } + + if (pcurs == CURSOR_DISARM && pcursobj == -1) { + NewCursor(CURSOR_HAND); + return true; + } + + return false; +} + +void diablo_pause_game() +{ + if (!gbIsMultiplayer) { + if (PauseMode != 0) { + PauseMode = 0; + } else { + PauseMode = 2; + sound_stop(); + track_repeat_walk(false); + } + force_redraw = 255; + } +} + +bool PressEscKey() +{ + bool rv = false; + + if (DoomFlag) { + doom_close(); + rv = true; + } + + if (HelpFlag) { + HelpFlag = false; + rv = true; + } + + if (qtextflag) { + qtextflag = false; + stream_stop(); + rv = true; + } + + if (stextflag != STORE_NONE) { + StoreESC(); + rv = true; + } + + if (msgflag != EMSG_NONE) { + msgdelay = 0; + rv = true; + } + + if (talkflag) { + control_reset_talk(); + rv = true; + } + + if (dropGoldFlag) { + control_drop_gold(DVL_VK_ESCAPE); + rv = true; + } + + if (spselflag) { + spselflag = false; + rv = true; + } + + if (invflag || chrflag || sbookflag || QuestLogIsOpen) { + ClosePanels(); + rv = true; + } + + return rv; +} + +void DisableInputWndProc(uint32_t uMsg, int32_t /*wParam*/, int32_t lParam) +{ + switch (uMsg) { + case DVL_WM_KEYDOWN: + case DVL_WM_KEYUP: + case DVL_WM_CHAR: + case DVL_WM_SYSKEYDOWN: + case DVL_WM_SYSCOMMAND: + return; + case DVL_WM_MOUSEMOVE: + GetMousePos(lParam); + return; + case DVL_WM_LBUTTONDOWN: + if (sgbMouseDown != CLICK_NONE) + return; + sgbMouseDown = CLICK_LEFT; + return; + case DVL_WM_LBUTTONUP: + if (sgbMouseDown != CLICK_LEFT) + return; + sgbMouseDown = CLICK_NONE; + return; + case DVL_WM_RBUTTONDOWN: + if (sgbMouseDown != CLICK_NONE) + return; + sgbMouseDown = CLICK_RIGHT; + return; + case DVL_WM_RBUTTONUP: + if (sgbMouseDown != CLICK_RIGHT) + return; + sgbMouseDown = CLICK_NONE; + return; + case DVL_WM_CAPTURECHANGED: + sgbMouseDown = CLICK_NONE; + return; + } + + MainWndProc(uMsg); +} + +void GM_Game(uint32_t uMsg, int32_t wParam, int32_t lParam) +{ + switch (uMsg) { + case DVL_WM_KEYDOWN: + PressKey(wParam); + return; + case DVL_WM_KEYUP: + ReleaseKey(wParam); + return; + case DVL_WM_CHAR: + PressChar(wParam); + return; + case DVL_WM_SYSKEYDOWN: + if (PressSysKey(wParam)) + return; + break; + case DVL_WM_SYSCOMMAND: + if (wParam == DVL_SC_CLOSE) { + gbRunGame = false; + gbRunGameResult = false; + return; + } + break; + case DVL_WM_MOUSEMOVE: + GetMousePos(lParam); + gmenu_on_mouse_move(); + return; + case DVL_WM_LBUTTONDOWN: + GetMousePos(lParam); + if (sgbMouseDown == CLICK_NONE) { + sgbMouseDown = CLICK_LEFT; + track_repeat_walk(LeftMouseDown(wParam)); + } + return; + case DVL_WM_LBUTTONUP: + GetMousePos(lParam); + if (sgbMouseDown == CLICK_LEFT) { + sgbMouseDown = CLICK_NONE; + LeftMouseUp(wParam); + track_repeat_walk(false); + } + return; + case DVL_WM_RBUTTONDOWN: + GetMousePos(lParam); + if (sgbMouseDown == CLICK_NONE) { + sgbMouseDown = CLICK_RIGHT; + RightMouseDown(); + } + return; + case DVL_WM_RBUTTONUP: + GetMousePos(lParam); + if (sgbMouseDown == CLICK_RIGHT) { + sgbMouseDown = CLICK_NONE; + } + return; + case DVL_WM_CAPTURECHANGED: + sgbMouseDown = CLICK_NONE; + track_repeat_walk(false); + break; + case WM_DIABNEXTLVL: + case WM_DIABPREVLVL: + case WM_DIABRTNLVL: + case WM_DIABSETLVL: + case WM_DIABWARPLVL: + case WM_DIABTOWNWARP: + case WM_DIABTWARPUP: + case WM_DIABRETOWN: + if (gbIsMultiplayer) + pfile_write_hero(); + nthread_ignore_mutex(true); + PaletteFadeOut(8); + sound_stop(); + music_stop(); + track_repeat_walk(false); + sgbMouseDown = CLICK_NONE; + ShowProgress((interface_mode)uMsg); + force_redraw = 255; + DrawAndBlit(); + LoadPWaterPalette(); + if (gbRunGame) + PaletteFadeIn(8); + nthread_ignore_mutex(false); + gbGameLoopStartup = true; + return; + } + + MainWndProc(uMsg); +} + +void LoadGameLevel(bool firstflag, lvl_entry lvldir) +{ + if (setseed != 0) + glSeedTbl[currlevel] = setseed; + + music_stop(); + if (pcurs > CURSOR_HAND && pcurs < CURSOR_FIRSTITEM) { + NewCursor(CURSOR_HAND); + } + SetRndSeed(glSeedTbl[currlevel]); + IncProgress(); + MakeLightTable(); + LoadLvlGFX(); + IncProgress(); + + if (firstflag) { + InitInv(); + InitQuestText(); + InitStores(); + InitAutomapOnce(); + InitHelp(); + InitText(); + } + + SetRndSeed(glSeedTbl[currlevel]); + + if (leveltype == DTYPE_TOWN) + SetupTownStores(); + + IncProgress(); + InitAutomap(); + + if (leveltype != DTYPE_TOWN && lvldir != ENTRY_LOAD) { + InitLighting(); + InitVision(); + } + + InitLevelMonsters(); + IncProgress(); + + auto &myPlayer = Players[MyPlayerId]; + + if (!setlevel) { + CreateLevel(lvldir); + IncProgress(); + FillSolidBlockTbls(); + SetRndSeed(glSeedTbl[currlevel]); + + if (leveltype != DTYPE_TOWN) { + GetLevelMTypes(); + InitThemes(); + LoadAllGFX(); + } else { + IncProgress(); + IncProgress(); + InitMissileGFX(); + IncProgress(); + IncProgress(); + } + + IncProgress(); + + if (lvldir == ENTRY_RTNLVL) + GetReturnLvlPos(); + if (lvldir == ENTRY_WARPLVL) + GetPortalLvlPos(); + + IncProgress(); + + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = Players[i]; + if (player.plractive && currlevel == player.plrlevel) { + InitPlayerGFX(player); + if (lvldir != ENTRY_LOAD) + InitPlayer(i, firstflag); + } + } + + PlayDungMsgs(); + InitMultiView(); + IncProgress(); + + bool visited = false; + int players = gbIsMultiplayer ? MAX_PLRS : 1; + for (int i = 0; i < players; i++) { + auto &player = Players[i]; + if (player.plractive) + visited = visited || player._pLvlVisited[currlevel]; + } + + SetRndSeed(glSeedTbl[currlevel]); + + if (leveltype != DTYPE_TOWN) { + if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pLvlVisited[currlevel] || gbIsMultiplayer) { + HoldThemeRooms(); + glMid1Seed[currlevel] = GetLCGEngineState(); + InitMonsters(); + glMid2Seed[currlevel] = GetLCGEngineState(); + IncProgress(); + InitObjects(); + InitItems(); + if (currlevel < 17) + CreateThemeRooms(); + IncProgress(); + glMid3Seed[currlevel] = GetLCGEngineState(); + InitMissiles(); + InitDead(); + glEndSeed[currlevel] = GetLCGEngineState(); + + if (gbIsMultiplayer) + DeltaLoadLevel(); + + IncProgress(); + SavePreLighting(); + } else { + HoldThemeRooms(); + InitMonsters(); + InitMissiles(); + InitDead(); + IncProgress(); + LoadLevel(); + IncProgress(); + } + } else { + for (int i = 0; i < MAXDUNX; i++) { // NOLINT(modernize-loop-convert) + for (int j = 0; j < MAXDUNY; j++) { + dFlags[i][j] |= BFLAG_LIT; + } + } + + InitTowners(); + InitItems(); + InitMissiles(); + IncProgress(); + + if (!firstflag && lvldir != ENTRY_LOAD && myPlayer._pLvlVisited[currlevel] && !gbIsMultiplayer) + LoadLevel(); + if (gbIsMultiplayer) + DeltaLoadLevel(); + + IncProgress(); + } + if (!gbIsMultiplayer) + ResyncQuests(); + else + ResyncMPQuests(); + } else { + LoadSetMap(); + IncProgress(); + GetLevelMTypes(); + IncProgress(); + InitMonsters(); + IncProgress(); + InitMissileGFX(); + IncProgress(); + InitDead(); + IncProgress(); + FillSolidBlockTbls(); + IncProgress(); + + if (lvldir == ENTRY_WARPLVL) + GetPortalLvlPos(); + IncProgress(); + + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = Players[i]; + if (player.plractive && currlevel == player.plrlevel) { + InitPlayerGFX(player); + if (lvldir != ENTRY_LOAD) + InitPlayer(i, firstflag); + } + } + IncProgress(); + + InitMultiView(); + IncProgress(); + + if (firstflag || lvldir == ENTRY_LOAD || !myPlayer._pSLvlVisited[setlvlnum]) { + InitItems(); + SavePreLighting(); + } else { + LoadLevel(); + } + + InitMissiles(); + IncProgress(); + } + + SyncPortals(); + + for (int i = 0; i < MAX_PLRS; i++) { + auto &player = Players[i]; + if (player.plractive && player.plrlevel == currlevel && (!player._pLvlChanging || i == MyPlayerId)) { + if (player._pHitPoints > 0) { + if (!gbIsMultiplayer) + dPlayer[player.position.tile.x][player.position.tile.y] = i + 1; + else + SyncInitPlrPos(i); + } else { + dFlags[player.position.tile.x][player.position.tile.y] |= BFLAG_DEAD_PLAYER; + } + } + } + + SetDungeonMicros(); + + InitLightMax(); + IncProgress(); + IncProgress(); + + if (firstflag) { + InitControlPan(); + } + IncProgress(); + UpdateMonsterLights(); + if (leveltype != DTYPE_TOWN) { + ProcessLightList(); + ProcessVisionList(); + } + + if (currlevel >= 21) { + if (currlevel == 21) { + CornerstoneLoad(CornerStone.position); + } + if (Quests[Q_NAKRUL]._qactive == QUEST_DONE && currlevel == 24) { + SyncNakrulRoom(); + } + } + + if (currlevel >= 17) + music_start(currlevel > 20 ? TMUSIC_L5 : TMUSIC_L6); + else + music_start(leveltype); + + while (!IncProgress()) + ; + + if (!gbIsSpawn && setlevel && setlvlnum == SL_SKELKING && Quests[Q_SKELKING]._qactive == QUEST_ACTIVE) + PlaySFX(USFX_SKING1); +} + +/** + * @param bStartup Process additional ticks before returning + */ +void game_loop(bool bStartup) +{ + uint16_t wait = bStartup ? sgGameInitInfo.nTickRate * 3 : 3; + + for (unsigned i = 0; i < wait; i++) { + if (!multi_handle_delta()) { + TimeoutCursor(true); + break; + } + TimeoutCursor(false); + GameLogic(); + + if (!gbRunGame || !gbIsMultiplayer || !nthread_has_500ms_passed()) + break; + } +} + +void diablo_color_cyc_logic() +{ + if (!sgOptions.Graphics.bColorCycling) + return; + + if (leveltype == DTYPE_HELL) { + lighting_color_cycling(); + } else if (currlevel >= 21) { + palette_update_crypt(); + } else if (currlevel >= 17) { + palette_update_hive(); + } else if (setlevel && setlvlnum == Quests[Q_PWATER]._qslvl) { + UpdatePWaterPalette(); + } else if (leveltype == DTYPE_CAVES) { + palette_update_caves(); + } +} + } // namespace devilution diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index f72662f4d..002839583 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -503,8 +503,6 @@ BYTE CornerstoneRoomPattern[27] = { */ BYTE L5ConvTbl[16] = { 22, 13, 1, 13, 2, 13, 13, 13, 4, 13, 1, 13, 2, 13, 16, 13 }; -} // namespace - void DRLG_InitL5Vals() { for (int j = 0; j < MAXDUNY; j++) { @@ -881,52 +879,6 @@ static void DrlgL1Floor() } } -void DRLG_LPass3(int lv) -{ - { - MegaTile mega = pMegaTiles[lv]; - int v1 = SDL_SwapLE16(mega.micro1) + 1; - int v2 = SDL_SwapLE16(mega.micro2) + 1; - int v3 = SDL_SwapLE16(mega.micro3) + 1; - int v4 = SDL_SwapLE16(mega.micro4) + 1; - - for (int j = 0; j < MAXDUNY; j += 2) { - for (int i = 0; i < MAXDUNX; i += 2) { - dPiece[i + 0][j + 0] = v1; - dPiece[i + 1][j + 0] = v2; - dPiece[i + 0][j + 1] = v3; - dPiece[i + 1][j + 1] = v4; - } - } - } - - int yy = 16; - for (int j = 0; j < DMAXY; j++) { - int xx = 16; - for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert) - int v1 = 0; - int v2 = 0; - int v3 = 0; - int v4 = 0; - - int tileId = dungeon[i][j] - 1; - if (tileId >= 0) { - MegaTile mega = pMegaTiles[tileId]; - v1 = SDL_SwapLE16(mega.micro1) + 1; - v2 = SDL_SwapLE16(mega.micro2) + 1; - v3 = SDL_SwapLE16(mega.micro3) + 1; - v4 = SDL_SwapLE16(mega.micro4) + 1; - } - dPiece[xx + 0][yy + 0] = v1; - dPiece[xx + 1][yy + 0] = v2; - dPiece[xx + 0][yy + 1] = v3; - dPiece[xx + 1][yy + 1] = v4; - xx += 2; - } - yy += 2; - } -} - static void DrlgL1Pass3() { DRLG_LPass3(22 - 1); @@ -954,20 +906,6 @@ static void DrlgFreeL1Sp() L5pSetPiece = nullptr; } -void DRLG_Init_Globals() -{ - memset(dFlags, 0, sizeof(dFlags)); - memset(dPlayer, 0, sizeof(dPlayer)); - memset(dMonster, 0, sizeof(dMonster)); - memset(dDead, 0, sizeof(dDead)); - memset(dObject, 0, sizeof(dObject)); - memset(dItem, 0, sizeof(dItem)); - memset(dMissile, 0, sizeof(dMissile)); - memset(dSpecial, 0, sizeof(dSpecial)); - int8_t c = DisableLighting ? 0 : 15; - memset(dLight, c, sizeof(dLight)); -} - static void DrlgInitL1Vals() { int8_t pc; @@ -994,100 +932,6 @@ static void DrlgInitL1Vals() } } -void LoadL1Dungeon(const char *path, int vx, int vy) -{ - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - DRLG_InitTrans(); - - for (int j = 0; j < DMAXY; j++) { - for (int i = 0; i < DMAXX; i++) { - dungeon[i][j] = 22; - L5dflags[i][j] = 0; - } - } - - auto dunData = LoadFileInMem(path); - - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); - - const uint16_t *tileLayer = &dunData[2]; - - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(*tileLayer); - tileLayer++; - if (tileId != 0) { - dungeon[i][j] = tileId; - L5dflags[i][j] |= DLRG_PROTECTED; - } else { - dungeon[i][j] = 13; - } - } - } - - DrlgL1Floor(); - - ViewX = vx; - ViewY = vy; - - DrlgL1Pass3(); - DRLG_Init_Globals(); - - if (currlevel < 17) - DrlgInitL1Vals(); - - SetMapMonsters(dunData.get(), { 0, 0 }); - SetMapObjects(dunData.get(), 0, 0); -} - -void LoadPreL1Dungeon(const char *path) -{ - for (int j = 0; j < DMAXY; j++) { - for (int i = 0; i < DMAXX; i++) { - dungeon[i][j] = 22; - L5dflags[i][j] = 0; - } - } - - dminx = 16; - dminy = 16; - dmaxx = 96; - dmaxy = 96; - - auto dunData = LoadFileInMem(path); - - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); - - const uint16_t *tileLayer = &dunData[2]; - - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - uint8_t tileId = SDL_SwapLE16(*tileLayer); - tileLayer++; - if (tileId != 0) { - dungeon[i][j] = tileId; - L5dflags[i][j] |= DLRG_PROTECTED; - } else { - dungeon[i][j] = 13; - } - } - } - - DrlgL1Floor(); - - for (int j = 0; j < DMAXY; j++) { - for (int i = 0; i < DMAXX; i++) { - pdungeon[i][j] = dungeon[i][j]; - } - } -} - static void InitL5Dungeon() { for (int j = 0; j < DMAXY; j++) { @@ -1706,6 +1550,31 @@ static void L5tileFix() } } +void drlg_l1_set_corner_room(int rx1, int ry1) +{ + int rw = CornerstoneRoomPattern[0]; + int rh = CornerstoneRoomPattern[1]; + + setpc_x = rx1; + setpc_y = ry1; + setpc_w = rw; + setpc_h = rh; + + int sp = 2; + + for (int j = 0; j < rh; j++) { + for (int i = 0; i < rw; i++) { + if (CornerstoneRoomPattern[sp] != 0) { + dungeon[rx1 + i][ry1 + j] = CornerstoneRoomPattern[sp]; + L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; + } else { + dungeon[rx1 + i][ry1 + j] = 13; + } + sp++; + } + } +} + void drlg_l1_crypt_rndset(const BYTE *miniset, int rndper) { int sw = miniset[0]; @@ -1825,6 +1694,35 @@ static void DrlgL5SetRoom(int rx1, int ry1) } } +void drlg_l1_set_crypt_room(int rx1, int ry1) +{ + int rw = UberRoomPattern[0]; + int rh = UberRoomPattern[1]; + + UberRow = 2 * rx1 + 6; + UberCol = 2 * ry1 + 8; + setpc_x = rx1; + setpc_y = ry1; + setpc_w = rw; + setpc_h = rh; + IsUberRoomOpened = false; + IsUberLeverActivated = false; + + int sp = 2; + + for (int j = 0; j < rh; j++) { + for (int i = 0; i < rw; i++) { + if (UberRoomPattern[sp] != 0) { + dungeon[rx1 + i][ry1 + j] = UberRoomPattern[sp]; + L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; + } else { + dungeon[rx1 + i][ry1 + j] = 13; + } + sp++; + } + } +} + static void L5FillChambers() { if (HR1) @@ -2045,66 +1943,12 @@ static void L5FillChambers() } } -void drlg_l1_set_crypt_room(int rx1, int ry1) +static void DrlgL5FTransparencyValueR(int i, int j, int x, int y, int d) { - int rw = UberRoomPattern[0]; - int rh = UberRoomPattern[1]; - - UberRow = 2 * rx1 + 6; - UberCol = 2 * ry1 + 8; - setpc_x = rx1; - setpc_y = ry1; - setpc_w = rw; - setpc_h = rh; - IsUberRoomOpened = false; - IsUberLeverActivated = false; - - int sp = 2; - - for (int j = 0; j < rh; j++) { - for (int i = 0; i < rw; i++) { - if (UberRoomPattern[sp] != 0) { - dungeon[rx1 + i][ry1 + j] = UberRoomPattern[sp]; - L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; - } else { - dungeon[rx1 + i][ry1 + j] = 13; - } - sp++; - } - } -} - -void drlg_l1_set_corner_room(int rx1, int ry1) -{ - int rw = CornerstoneRoomPattern[0]; - int rh = CornerstoneRoomPattern[1]; - - setpc_x = rx1; - setpc_y = ry1; - setpc_w = rw; - setpc_h = rh; - - int sp = 2; - - for (int j = 0; j < rh; j++) { - for (int i = 0; i < rw; i++) { - if (CornerstoneRoomPattern[sp] != 0) { - dungeon[rx1 + i][ry1 + j] = CornerstoneRoomPattern[sp]; - L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED; - } else { - dungeon[rx1 + i][ry1 + j] = 13; - } - sp++; - } - } -} - -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) { - dTransVal[x][y] = TransVal; - dTransVal[x][y + 1] = TransVal; + if (dTransVal[x][y] != 0 || dungeon[i][j] != 13) { + if (d == 1) { + dTransVal[x][y] = TransVal; + dTransVal[x][y + 1] = TransVal; } if (d == 2) { dTransVal[x + 1][y] = TransVal; @@ -2251,6 +2095,129 @@ static void DrlgL5CornerFix() } } +void drlg_l1_crypt_pattern1(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern97, rndper); + drlg_l1_crypt_rndset(CryptPattern98, rndper); + drlg_l1_crypt_rndset(CryptPattern99, rndper); + drlg_l1_crypt_rndset(CryptPattern100, rndper); +} + +void drlg_l1_crypt_pattern2(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern46, rndper); + drlg_l1_crypt_rndset(CryptPattern47, rndper); + drlg_l1_crypt_rndset(CryptPattern48, rndper); + drlg_l1_crypt_rndset(CryptPattern49, rndper); + drlg_l1_crypt_rndset(CryptPattern50, rndper); + drlg_l1_crypt_rndset(CryptPattern51, rndper); + drlg_l1_crypt_rndset(CryptPattern52, rndper); + drlg_l1_crypt_rndset(CryptPattern53, rndper); + drlg_l1_crypt_rndset(CryptPattern54, rndper); + drlg_l1_crypt_rndset(CryptPattern55, rndper); + drlg_l1_crypt_rndset(CryptPattern56, rndper); + drlg_l1_crypt_rndset(CryptPattern57, rndper); + drlg_l1_crypt_rndset(CryptPattern58, rndper); + drlg_l1_crypt_rndset(CryptPattern59, rndper); + drlg_l1_crypt_rndset(CryptPattern60, rndper); + drlg_l1_crypt_rndset(CryptPattern61, rndper); + drlg_l1_crypt_rndset(CryptPattern62, rndper); +} + +void drlg_l1_crypt_pattern3(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern63, rndper); + drlg_l1_crypt_rndset(CryptPattern64, rndper); + drlg_l1_crypt_rndset(CryptPattern65, rndper); + drlg_l1_crypt_rndset(CryptPattern66, rndper); + drlg_l1_crypt_rndset(CryptPattern67, rndper); + drlg_l1_crypt_rndset(CryptPattern68, rndper); + drlg_l1_crypt_rndset(CryptPattern69, rndper); + drlg_l1_crypt_rndset(CryptPattern70, rndper); + drlg_l1_crypt_rndset(CryptPattern71, rndper); + drlg_l1_crypt_rndset(CryptPattern72, rndper); + drlg_l1_crypt_rndset(CryptPattern73, rndper); + drlg_l1_crypt_rndset(CryptPattern74, rndper); + drlg_l1_crypt_rndset(CryptPattern75, rndper); + drlg_l1_crypt_rndset(CryptPattern76, rndper); + drlg_l1_crypt_rndset(CryptPattern77, rndper); + drlg_l1_crypt_rndset(CryptPattern78, rndper); + drlg_l1_crypt_rndset(CryptPattern79, rndper); +} + +void drlg_l1_crypt_pattern4(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern80, rndper); + drlg_l1_crypt_rndset(CryptPattern81, rndper); + drlg_l1_crypt_rndset(CryptPattern82, rndper); + drlg_l1_crypt_rndset(CryptPattern83, rndper); + drlg_l1_crypt_rndset(CryptPattern84, rndper); + drlg_l1_crypt_rndset(CryptPattern85, rndper); + drlg_l1_crypt_rndset(CryptPattern86, rndper); + drlg_l1_crypt_rndset(CryptPattern87, rndper); + drlg_l1_crypt_rndset(CryptPattern88, rndper); + drlg_l1_crypt_rndset(CryptPattern89, rndper); + drlg_l1_crypt_rndset(CryptPattern90, rndper); + drlg_l1_crypt_rndset(CryptPattern91, rndper); + drlg_l1_crypt_rndset(CryptPattern92, rndper); + drlg_l1_crypt_rndset(CryptPattern93, rndper); + drlg_l1_crypt_rndset(CryptPattern94, rndper); + drlg_l1_crypt_rndset(CryptPattern95, rndper); + drlg_l1_crypt_rndset(CryptPattern96, rndper); +} + +void drlg_l1_crypt_pattern5(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern36, rndper); + drlg_l1_crypt_rndset(CryptPattern37, rndper); + drlg_l1_crypt_rndset(CryptPattern38, rndper); + drlg_l1_crypt_rndset(CryptPattern39, rndper); + drlg_l1_crypt_rndset(CryptPattern40, rndper); + drlg_l1_crypt_rndset(CryptPattern41, rndper); + drlg_l1_crypt_rndset(CryptPattern42, rndper); + drlg_l1_crypt_rndset(CryptPattern43, rndper); + drlg_l1_crypt_rndset(CryptPattern44, rndper); + drlg_l1_crypt_rndset(CryptPattern45, rndper); +} + +void drlg_l1_crypt_pattern6(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern10, rndper); + drlg_l1_crypt_rndset(CryptPattern12, rndper); + drlg_l1_crypt_rndset(CryptPattern11, rndper); + drlg_l1_crypt_rndset(CryptPattern13, rndper); + drlg_l1_crypt_rndset(CryptPattern14, rndper); + drlg_l1_crypt_rndset(CryptPattern15, rndper); + drlg_l1_crypt_rndset(CryptPattern16, rndper); + drlg_l1_crypt_rndset(CryptPattern17, rndper); + drlg_l1_crypt_rndset(CryptPattern18, rndper); + drlg_l1_crypt_rndset(CryptPattern19, rndper); + drlg_l1_crypt_rndset(CryptPattern20, rndper); + drlg_l1_crypt_rndset(CryptPattern21, rndper); + drlg_l1_crypt_rndset(CryptPattern22, rndper); + drlg_l1_crypt_rndset(CryptPattern23, rndper); + drlg_l1_crypt_rndset(CryptPattern24, rndper); + drlg_l1_crypt_rndset(CryptPattern25, rndper); + drlg_l1_crypt_rndset(CryptPattern26, rndper); + drlg_l1_crypt_rndset(CryptPattern27, rndper); + drlg_l1_crypt_rndset(CryptPattern28, rndper); + drlg_l1_crypt_rndset(CryptPattern29, rndper); + drlg_l1_crypt_rndset(CryptPattern30, rndper); + drlg_l1_crypt_rndset(CryptPattern31, rndper); + drlg_l1_crypt_rndset(CryptPattern32, rndper); + drlg_l1_crypt_rndset(CryptPattern33, rndper); + drlg_l1_crypt_rndset(CryptPattern34, rndper); + drlg_l1_crypt_rndset(CryptPattern35, rndper); +} + +void drlg_l1_crypt_pattern7(int rndper) +{ + drlg_l1_crypt_rndset(CryptPattern5, rndper); + drlg_l1_crypt_rndset(CryptPattern6, rndper); + drlg_l1_crypt_rndset(CryptPattern7, rndper); + drlg_l1_crypt_rndset(CryptPattern8, rndper); +} + static void DrlgL5(lvl_entry entry) { int minarea = 761; @@ -2476,6 +2443,162 @@ static void DrlgL5(lvl_entry entry) DRLG_CheckQuests(setpc_x, setpc_y); } +} // namespace + +void DRLG_LPass3(int lv) +{ + { + MegaTile mega = pMegaTiles[lv]; + int v1 = SDL_SwapLE16(mega.micro1) + 1; + int v2 = SDL_SwapLE16(mega.micro2) + 1; + int v3 = SDL_SwapLE16(mega.micro3) + 1; + int v4 = SDL_SwapLE16(mega.micro4) + 1; + + for (int j = 0; j < MAXDUNY; j += 2) { + for (int i = 0; i < MAXDUNX; i += 2) { + dPiece[i + 0][j + 0] = v1; + dPiece[i + 1][j + 0] = v2; + dPiece[i + 0][j + 1] = v3; + dPiece[i + 1][j + 1] = v4; + } + } + } + + int yy = 16; + for (int j = 0; j < DMAXY; j++) { + int xx = 16; + for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert) + int v1 = 0; + int v2 = 0; + int v3 = 0; + int v4 = 0; + + int tileId = dungeon[i][j] - 1; + if (tileId >= 0) { + MegaTile mega = pMegaTiles[tileId]; + v1 = SDL_SwapLE16(mega.micro1) + 1; + v2 = SDL_SwapLE16(mega.micro2) + 1; + v3 = SDL_SwapLE16(mega.micro3) + 1; + v4 = SDL_SwapLE16(mega.micro4) + 1; + } + dPiece[xx + 0][yy + 0] = v1; + dPiece[xx + 1][yy + 0] = v2; + dPiece[xx + 0][yy + 1] = v3; + dPiece[xx + 1][yy + 1] = v4; + xx += 2; + } + yy += 2; + } +} + +void DRLG_Init_Globals() +{ + memset(dFlags, 0, sizeof(dFlags)); + memset(dPlayer, 0, sizeof(dPlayer)); + memset(dMonster, 0, sizeof(dMonster)); + memset(dDead, 0, sizeof(dDead)); + memset(dObject, 0, sizeof(dObject)); + memset(dItem, 0, sizeof(dItem)); + memset(dMissile, 0, sizeof(dMissile)); + memset(dSpecial, 0, sizeof(dSpecial)); + int8_t c = DisableLighting ? 0 : 15; + memset(dLight, c, sizeof(dLight)); +} + +void LoadL1Dungeon(const char *path, int vx, int vy) +{ + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + DRLG_InitTrans(); + + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) { + dungeon[i][j] = 22; + L5dflags[i][j] = 0; + } + } + + auto dunData = LoadFileInMem(path); + + int width = SDL_SwapLE16(dunData[0]); + int height = SDL_SwapLE16(dunData[1]); + + const uint16_t *tileLayer = &dunData[2]; + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + uint8_t tileId = SDL_SwapLE16(*tileLayer); + tileLayer++; + if (tileId != 0) { + dungeon[i][j] = tileId; + L5dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 13; + } + } + } + + DrlgL1Floor(); + + ViewX = vx; + ViewY = vy; + + DrlgL1Pass3(); + DRLG_Init_Globals(); + + if (currlevel < 17) + DrlgInitL1Vals(); + + SetMapMonsters(dunData.get(), { 0, 0 }); + SetMapObjects(dunData.get(), 0, 0); +} + +void LoadPreL1Dungeon(const char *path) +{ + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) { + dungeon[i][j] = 22; + L5dflags[i][j] = 0; + } + } + + dminx = 16; + dminy = 16; + dmaxx = 96; + dmaxy = 96; + + auto dunData = LoadFileInMem(path); + + int width = SDL_SwapLE16(dunData[0]); + int height = SDL_SwapLE16(dunData[1]); + + const uint16_t *tileLayer = &dunData[2]; + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + uint8_t tileId = SDL_SwapLE16(*tileLayer); + tileLayer++; + if (tileId != 0) { + dungeon[i][j] = tileId; + L5dflags[i][j] |= DLRG_PROTECTED; + } else { + dungeon[i][j] = 13; + } + } + } + + DrlgL1Floor(); + + for (int j = 0; j < DMAXY; j++) { + for (int i = 0; i < DMAXX; i++) { + pdungeon[i][j] = dungeon[i][j]; + } + } +} + void CreateL5Dungeon(uint32_t rseed, lvl_entry entry) { SetRndSeed(rseed); @@ -2518,127 +2641,4 @@ void CreateL5Dungeon(uint32_t rseed, lvl_entry entry) } } -void drlg_l1_crypt_pattern1(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern97, rndper); - drlg_l1_crypt_rndset(CryptPattern98, rndper); - drlg_l1_crypt_rndset(CryptPattern99, rndper); - drlg_l1_crypt_rndset(CryptPattern100, rndper); -} - -void drlg_l1_crypt_pattern2(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern46, rndper); - drlg_l1_crypt_rndset(CryptPattern47, rndper); - drlg_l1_crypt_rndset(CryptPattern48, rndper); - drlg_l1_crypt_rndset(CryptPattern49, rndper); - drlg_l1_crypt_rndset(CryptPattern50, rndper); - drlg_l1_crypt_rndset(CryptPattern51, rndper); - drlg_l1_crypt_rndset(CryptPattern52, rndper); - drlg_l1_crypt_rndset(CryptPattern53, rndper); - drlg_l1_crypt_rndset(CryptPattern54, rndper); - drlg_l1_crypt_rndset(CryptPattern55, rndper); - drlg_l1_crypt_rndset(CryptPattern56, rndper); - drlg_l1_crypt_rndset(CryptPattern57, rndper); - drlg_l1_crypt_rndset(CryptPattern58, rndper); - drlg_l1_crypt_rndset(CryptPattern59, rndper); - drlg_l1_crypt_rndset(CryptPattern60, rndper); - drlg_l1_crypt_rndset(CryptPattern61, rndper); - drlg_l1_crypt_rndset(CryptPattern62, rndper); -} - -void drlg_l1_crypt_pattern3(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern63, rndper); - drlg_l1_crypt_rndset(CryptPattern64, rndper); - drlg_l1_crypt_rndset(CryptPattern65, rndper); - drlg_l1_crypt_rndset(CryptPattern66, rndper); - drlg_l1_crypt_rndset(CryptPattern67, rndper); - drlg_l1_crypt_rndset(CryptPattern68, rndper); - drlg_l1_crypt_rndset(CryptPattern69, rndper); - drlg_l1_crypt_rndset(CryptPattern70, rndper); - drlg_l1_crypt_rndset(CryptPattern71, rndper); - drlg_l1_crypt_rndset(CryptPattern72, rndper); - drlg_l1_crypt_rndset(CryptPattern73, rndper); - drlg_l1_crypt_rndset(CryptPattern74, rndper); - drlg_l1_crypt_rndset(CryptPattern75, rndper); - drlg_l1_crypt_rndset(CryptPattern76, rndper); - drlg_l1_crypt_rndset(CryptPattern77, rndper); - drlg_l1_crypt_rndset(CryptPattern78, rndper); - drlg_l1_crypt_rndset(CryptPattern79, rndper); -} - -void drlg_l1_crypt_pattern4(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern80, rndper); - drlg_l1_crypt_rndset(CryptPattern81, rndper); - drlg_l1_crypt_rndset(CryptPattern82, rndper); - drlg_l1_crypt_rndset(CryptPattern83, rndper); - drlg_l1_crypt_rndset(CryptPattern84, rndper); - drlg_l1_crypt_rndset(CryptPattern85, rndper); - drlg_l1_crypt_rndset(CryptPattern86, rndper); - drlg_l1_crypt_rndset(CryptPattern87, rndper); - drlg_l1_crypt_rndset(CryptPattern88, rndper); - drlg_l1_crypt_rndset(CryptPattern89, rndper); - drlg_l1_crypt_rndset(CryptPattern90, rndper); - drlg_l1_crypt_rndset(CryptPattern91, rndper); - drlg_l1_crypt_rndset(CryptPattern92, rndper); - drlg_l1_crypt_rndset(CryptPattern93, rndper); - drlg_l1_crypt_rndset(CryptPattern94, rndper); - drlg_l1_crypt_rndset(CryptPattern95, rndper); - drlg_l1_crypt_rndset(CryptPattern96, rndper); -} - -void drlg_l1_crypt_pattern5(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern36, rndper); - drlg_l1_crypt_rndset(CryptPattern37, rndper); - drlg_l1_crypt_rndset(CryptPattern38, rndper); - drlg_l1_crypt_rndset(CryptPattern39, rndper); - drlg_l1_crypt_rndset(CryptPattern40, rndper); - drlg_l1_crypt_rndset(CryptPattern41, rndper); - drlg_l1_crypt_rndset(CryptPattern42, rndper); - drlg_l1_crypt_rndset(CryptPattern43, rndper); - drlg_l1_crypt_rndset(CryptPattern44, rndper); - drlg_l1_crypt_rndset(CryptPattern45, rndper); -} - -void drlg_l1_crypt_pattern6(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern10, rndper); - drlg_l1_crypt_rndset(CryptPattern12, rndper); - drlg_l1_crypt_rndset(CryptPattern11, rndper); - drlg_l1_crypt_rndset(CryptPattern13, rndper); - drlg_l1_crypt_rndset(CryptPattern14, rndper); - drlg_l1_crypt_rndset(CryptPattern15, rndper); - drlg_l1_crypt_rndset(CryptPattern16, rndper); - drlg_l1_crypt_rndset(CryptPattern17, rndper); - drlg_l1_crypt_rndset(CryptPattern18, rndper); - drlg_l1_crypt_rndset(CryptPattern19, rndper); - drlg_l1_crypt_rndset(CryptPattern20, rndper); - drlg_l1_crypt_rndset(CryptPattern21, rndper); - drlg_l1_crypt_rndset(CryptPattern22, rndper); - drlg_l1_crypt_rndset(CryptPattern23, rndper); - drlg_l1_crypt_rndset(CryptPattern24, rndper); - drlg_l1_crypt_rndset(CryptPattern25, rndper); - drlg_l1_crypt_rndset(CryptPattern26, rndper); - drlg_l1_crypt_rndset(CryptPattern27, rndper); - drlg_l1_crypt_rndset(CryptPattern28, rndper); - drlg_l1_crypt_rndset(CryptPattern29, rndper); - drlg_l1_crypt_rndset(CryptPattern30, rndper); - drlg_l1_crypt_rndset(CryptPattern31, rndper); - drlg_l1_crypt_rndset(CryptPattern32, rndper); - drlg_l1_crypt_rndset(CryptPattern33, rndper); - drlg_l1_crypt_rndset(CryptPattern34, rndper); - drlg_l1_crypt_rndset(CryptPattern35, rndper); -} - -void drlg_l1_crypt_pattern7(int rndper) -{ - drlg_l1_crypt_rndset(CryptPattern5, rndper); - drlg_l1_crypt_rndset(CryptPattern6, rndper); - drlg_l1_crypt_rndset(CryptPattern7, rndper); - drlg_l1_crypt_rndset(CryptPattern8, rndper); -} - } // namespace devilution diff --git a/Source/drlg_l1.h b/Source/drlg_l1.h index 372569475..5fa9c3f43 100644 --- a/Source/drlg_l1.h +++ b/Source/drlg_l1.h @@ -22,14 +22,5 @@ void DRLG_Init_Globals(); void LoadL1Dungeon(const char *path, int vx, int vy); void LoadPreL1Dungeon(const char *path); void CreateL5Dungeon(uint32_t rseed, lvl_entry entry); -void drlg_l1_set_crypt_room(int rx1, int ry1); -void drlg_l1_set_corner_room(int rx1, int ry1); -void drlg_l1_crypt_pattern1(int rndper); -void drlg_l1_crypt_pattern2(int rndper); -void drlg_l1_crypt_pattern3(int rndper); -void drlg_l1_crypt_pattern4(int rndper); -void drlg_l1_crypt_pattern5(int rndper); -void drlg_l1_crypt_pattern6(int rndper); -void drlg_l1_crypt_pattern7(int rndper); } // namespace devilution