From 9ebdb6db69b03338e2c6b9f737d5f23b626e1bae Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 6 Jul 2021 02:13:11 +0200 Subject: [PATCH] General clean up --- Source/DiabloUI/credits.cpp | 12 +- Source/DiabloUI/credits_lines.cpp | 4 +- Source/DiabloUI/credits_lines.h | 4 +- Source/DiabloUI/selhero.cpp | 6 - Source/automap.cpp | 2 +- Source/control.cpp | 2 +- Source/controls/devices/joystick.cpp | 2 - Source/controls/game_controls.cpp | 1 - Source/controls/keymapper.cpp | 14 +- Source/controls/keymapper.hpp | 12 +- Source/controls/plrctrls.cpp | 332 +++++++++++++-------------- Source/controls/touch.cpp | 6 +- Source/diablo.cpp | 49 ++-- Source/drlg_l1.cpp | 56 ++--- Source/drlg_l2.cpp | 22 +- Source/drlg_l3.cpp | 42 ++-- Source/drlg_l4.cpp | 44 ++-- Source/gmenu.cpp | 20 +- Source/help.cpp | 8 +- Source/interfac.cpp | 2 +- Source/items.cpp | 3 +- Source/lighting.cpp | 6 +- Source/monster.cpp | 10 +- Source/nthread.h | 4 +- Source/options.cpp | 4 +- Source/path.cpp | 25 +- Source/path.h | 4 +- Source/player.cpp | 8 +- Source/qol/autopickup.cpp | 9 +- Source/scrollrt.cpp | 16 +- Source/setmaps.cpp | 2 +- Source/setmaps.h | 2 +- Source/sound.cpp | 12 +- Source/stores.cpp | 22 +- Source/stores.h | 2 +- Source/utils/soundsample.cpp | 12 +- 36 files changed, 388 insertions(+), 393 deletions(-) diff --git a/Source/DiabloUI/credits.cpp b/Source/DiabloUI/credits.cpp index ecff4b1fc..2c57e59cb 100644 --- a/Source/DiabloUI/credits.cpp +++ b/Source/DiabloUI/credits.cpp @@ -26,7 +26,7 @@ const int ShadowOffsetX = 2; const int ShadowOffsetY = 2; const int LINE_H = 22; -char const *const *text; +char const *const *Text; std::size_t textLines; // The maximum number of visible lines is the number of whole lines @@ -66,7 +66,7 @@ SDL_Surface *RenderText(const char *text, SDL_Color color) CachedLine PrepareLine(std::size_t index) { - const char *contents = _(text[index]); + const char *contents = _(Text[index]); while (contents[0] == '\t') ++contents; @@ -182,7 +182,7 @@ void CreditsRenderer::Render() Sint16 destX = PANEL_LEFT + VIEWPORT.x + 31; int j = 0; - while (text[line.mIndex][j++] == '\t') + while (Text[line.mIndex][j++] == '\t') destX += 40; SDL_Rect dstRect = { destX, destY, 0, 0 }; @@ -234,8 +234,8 @@ bool TextDialog() bool UiCreditsDialog() { - text = CREDITS_LINES; - textLines = CREDITS_LINES_SIZE; + Text = CreditLines; + textLines = CreditLinesSize; LoadArt("ui_art\\creditsw.pcx", &ArtBackgroundWidescreen); LoadBackgroundArt("ui_art\\credits.pcx"); @@ -245,7 +245,7 @@ bool UiCreditsDialog() bool UiSupportDialog() { - text = SupportLines; + Text = SupportLines; textLines = SupportLinesSize; if (gbIsHellfire) { diff --git a/Source/DiabloUI/credits_lines.cpp b/Source/DiabloUI/credits_lines.cpp index 55719437b..16abb3cef 100644 --- a/Source/DiabloUI/credits_lines.cpp +++ b/Source/DiabloUI/credits_lines.cpp @@ -3,7 +3,7 @@ namespace devilution { -const char *const CREDITS_LINES[] = { +const char *const CreditLines[] = { N_("Game Design"), " Blizzard North", "", @@ -552,6 +552,6 @@ const char *const CREDITS_LINES[] = { " " }; -const std::size_t CREDITS_LINES_SIZE = sizeof(CREDITS_LINES) / sizeof(CREDITS_LINES[0]); +const std::size_t CreditLinesSize = sizeof(CreditLines) / sizeof(CreditLines[0]); } // namespace devilution diff --git a/Source/DiabloUI/credits_lines.h b/Source/DiabloUI/credits_lines.h index fcdd71732..81f29ddf6 100644 --- a/Source/DiabloUI/credits_lines.h +++ b/Source/DiabloUI/credits_lines.h @@ -2,7 +2,7 @@ namespace devilution { -extern const char *const CREDITS_LINES[]; -extern const std::size_t CREDITS_LINES_SIZE; +extern const char *const CreditLines[]; +extern const std::size_t CreditLinesSize; } // namespace devilution diff --git a/Source/DiabloUI/selhero.cpp b/Source/DiabloUI/selhero.cpp index f50c44f80..8f563fcae 100644 --- a/Source/DiabloUI/selhero.cpp +++ b/Source/DiabloUI/selhero.cpp @@ -44,8 +44,6 @@ std::vector vecSelDlgItems; UiImage *SELHERO_DIALOG_HERO_IMG; -bool bUIElementsLoaded = false; - void SelheroListFocus(int value); void SelheroListSelect(int value); void SelheroListEsc(); @@ -92,8 +90,6 @@ void SelheroFree() SelheroFreeDlgItems(); SelheroFreeListItems(); UnloadScrollBar(); - - bUIElementsLoaded = false; } void SelheroSetStats() @@ -572,8 +568,6 @@ static void UiSelHeroDialog( _selhero_selections *dlgresult, char (*name)[16]) { - bUIElementsLoaded = true; - do { gfnHeroInfo = fninfo; gfnHeroCreate = fncreate; diff --git a/Source/automap.cpp b/Source/automap.cpp index 91915e5ab..c93972266 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -400,7 +400,7 @@ void DrawAutomapText(const Surface &out) } if (setlevel) { - DrawString(out, _(quest_level_names[setlvlnum]), linePosition); + DrawString(out, _(QuestLevelNames[setlvlnum]), linePosition); return; } diff --git a/Source/control.cpp b/Source/control.cpp index 35d951db3..52091e906 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -445,7 +445,7 @@ void DrawSpellList(const Surface &out) } for (int t = 0; t < 4; t++) { if (myPlayer._pSplHotKey[t] == pSpell && myPlayer._pSplTHotKey[t] == pSplType) { - auto hotkeyName = keymapper.keyNameForAction(quickSpellActionIndexes[t]); + auto hotkeyName = keymapper.KeyNameForAction(quickSpellActionIndexes[t]); PrintSBookHotkey(out, location, hotkeyName); strcpy(tempstr, fmt::format(_("Spell Hotkey {:s}"), hotkeyName.c_str()).c_str()); AddPanelString(tempstr); diff --git a/Source/controls/devices/joystick.cpp b/Source/controls/devices/joystick.cpp index b17e06056..f731f6ea6 100644 --- a/Source/controls/devices/joystick.cpp +++ b/Source/controls/devices/joystick.cpp @@ -245,7 +245,6 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event) default: return false; } - return true; } void Joystick::Add(int deviceIndex) @@ -311,7 +310,6 @@ Joystick *Joystick::Get(const SDL_Event &event) case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: return Get(event.jbutton.which); - return Get(event.jbutton.which); default: return nullptr; #else diff --git a/Source/controls/game_controls.cpp b/Source/controls/game_controls.cpp index bd6e12b4c..5bb2d2c45 100644 --- a/Source/controls/game_controls.cpp +++ b/Source/controls/game_controls.cpp @@ -157,7 +157,6 @@ bool GetGameAction(const SDL_Event &event, ControllerButtonEvent ctrlEvent, Game case ControllerButton_BUTTON_START: case ControllerButton_BUTTON_BACK: return true; - break; default: break; } diff --git a/Source/controls/keymapper.cpp b/Source/controls/keymapper.cpp index e5615386d..00a783673 100644 --- a/Source/controls/keymapper.cpp +++ b/Source/controls/keymapper.cpp @@ -38,14 +38,14 @@ Keymapper::Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction g } } -Keymapper::ActionIndex Keymapper::addAction(const Action &action) +Keymapper::ActionIndex Keymapper::AddAction(const Action &action) { actions.emplace_back(action); return actions.size() - 1; } -void Keymapper::keyPressed(int key) const +void Keymapper::KeyPressed(int key) const { auto it = keyIDToAction.find(key); if (it == keyIDToAction.end()) @@ -61,7 +61,7 @@ void Keymapper::keyPressed(int key) const action(); } -std::string Keymapper::keyNameForAction(ActionIndex actionIndex) const +std::string Keymapper::KeyNameForAction(ActionIndex actionIndex) const { assert(actionIndex < actions.size()); auto key = actions[actionIndex].key; @@ -70,7 +70,7 @@ std::string Keymapper::keyNameForAction(ActionIndex actionIndex) const return it->second; } -void Keymapper::save() const +void Keymapper::Save() const { // Use the action vector to go though the actions to keep the same order. for (const auto &action : actions) { @@ -89,12 +89,12 @@ void Keymapper::save() const } } -void Keymapper::load() +void Keymapper::Load() { keyIDToAction.clear(); for (auto &action : actions) { - auto key = getActionKey(action); + auto key = GetActionKey(action); action.key = key; if (key == DVL_VK_INVALID) { // Skip if the action has no key bound to it. @@ -106,7 +106,7 @@ void Keymapper::load() } } -int Keymapper::getActionKey(const Keymapper::Action &action) +int Keymapper::GetActionKey(const Keymapper::Action &action) { auto key = getKeyFunction(action.name); if (key.empty()) diff --git a/Source/controls/keymapper.hpp b/Source/controls/keymapper.hpp index f04ae81f2..ac44354d0 100644 --- a/Source/controls/keymapper.hpp +++ b/Source/controls/keymapper.hpp @@ -59,14 +59,14 @@ public: */ Keymapper(SetConfigKeyFunction setKeyFunction, GetConfigKeyFunction getKeyFunction); - ActionIndex addAction(const Action &action); - void keyPressed(int key) const; - std::string keyNameForAction(ActionIndex actionIndex) const; - void save() const; - void load(); + ActionIndex AddAction(const Action &action); + void KeyPressed(int key) const; + std::string KeyNameForAction(ActionIndex actionIndex) const; + void Save() const; + void Load(); private: - int getActionKey(const Action &action); + int GetActionKey(const Action &action); std::vector actions; std::unordered_map> keyIDToAction; diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 439ef3851..6d178d5ab 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -45,7 +45,7 @@ bool InGameMenu() namespace { -int slot = SLOTXY_INV_FIRST; +int Slot = SLOTXY_INV_FIRST; /** * Number of angles to turn to face the coordinate @@ -257,9 +257,9 @@ void FindMeleeTarget() SearchNode node = queue.front(); queue.pop_front(); - for (int i = 0; i < 8; i++) { - const int dx = node.x + pathxdir[i]; - const int dy = node.y + pathydir[i]; + for (auto pathDir : PathDirs) { + const int dx = node.x + pathDir.deltaX; + const int dy = node.y + pathDir.deltaY; if (visited[dx][dy]) continue; // already visisted @@ -577,9 +577,9 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId) if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { int ig = slot - SLOTXY_INV_FIRST; auto &myPlayer = Players[MyPlayerId]; - char ii = myPlayer.InvGrid[ig]; + int8_t ii = myPlayer.InvGrid[ig]; if (ii != 0) { - int iv = ii; + int8_t iv = ii; if (ii <= 0) { iv = -ii; } @@ -605,29 +605,29 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId) void ResetInvCursorPosition() { Point mousePos {}; - if (slot < SLOTXY_INV_FIRST) { - mousePos = InvGetEquipSlotCoordFromInvSlot((inv_xy_slot)slot); - } else if (slot < SLOTXY_BELT_FIRST) { + if (Slot < SLOTXY_INV_FIRST) { + mousePos = InvGetEquipSlotCoordFromInvSlot((inv_xy_slot)Slot); + } else if (Slot < SLOTXY_BELT_FIRST) { char itemInvId; - auto itemSize = GetItemSizeOnSlot(slot, itemInvId); + auto itemSize = GetItemSizeOnSlot(Slot, itemInvId); // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId if (itemInvId < 0) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { if (Players[MyPlayerId].InvGrid[s] == -itemInvId) { - slot = SLOTXY_INV_FIRST + s; + Slot = SLOTXY_INV_FIRST + s; break; } } } // offset the slot to always move to the top-left most slot of that item - slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); - mousePos = InvGetSlotCoord(slot); + Slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); + mousePos = InvGetSlotCoord(Slot); mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; } else { - mousePos = BeltGetSlotCoord(slot); + mousePos = BeltGetSlotCoord(Slot); } mousePos.x += (InventorySlotSizeInPixels.width / 2); @@ -649,271 +649,271 @@ void InvMove(AxisDirection dir) return; char itemInvId; - auto itemSize = GetItemSizeOnSlot(slot, itemInvId); + auto itemSize = GetItemSizeOnSlot(Slot, itemInvId); Point mousePos = MousePosition; const bool isHoldingItem = pcurs > 1; // normalize slots - if (slot < 0) - slot = 0; - else if (slot >= SLOTXY_HEAD_FIRST && slot <= SLOTXY_HEAD_LAST) - slot = SLOTXY_HEAD_FIRST; - else if (slot >= SLOTXY_HAND_LEFT_FIRST && slot <= SLOTXY_HAND_LEFT_LAST) - slot = SLOTXY_HAND_LEFT_FIRST; - else if (slot >= SLOTXY_CHEST_FIRST && slot <= SLOTXY_CHEST_LAST) - slot = SLOTXY_CHEST_FIRST; - else if (slot >= SLOTXY_HAND_RIGHT_FIRST && slot <= SLOTXY_HAND_RIGHT_LAST) - slot = SLOTXY_HAND_RIGHT_FIRST; - else if (slot > SLOTXY_BELT_LAST) - slot = SLOTXY_BELT_LAST; - - const int initialSlot = slot; + if (Slot < 0) + Slot = 0; + else if (Slot >= SLOTXY_HEAD_FIRST && Slot <= SLOTXY_HEAD_LAST) + Slot = SLOTXY_HEAD_FIRST; + else if (Slot >= SLOTXY_HAND_LEFT_FIRST && Slot <= SLOTXY_HAND_LEFT_LAST) + Slot = SLOTXY_HAND_LEFT_FIRST; + else if (Slot >= SLOTXY_CHEST_FIRST && Slot <= SLOTXY_CHEST_LAST) + Slot = SLOTXY_CHEST_FIRST; + else if (Slot >= SLOTXY_HAND_RIGHT_FIRST && Slot <= SLOTXY_HAND_RIGHT_LAST) + Slot = SLOTXY_HAND_RIGHT_FIRST; + else if (Slot > SLOTXY_BELT_LAST) + Slot = SLOTXY_BELT_LAST; + + const int initialSlot = Slot; auto &myPlayer = Players[MyPlayerId]; // when item is on cursor (pcurs > 1), this is the real cursor XY if (dir.x == AxisDirectionX_LEFT) { if (isHoldingItem) { - if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { - if (slot == SLOTXY_INV_ROW1_FIRST || slot == SLOTXY_INV_ROW2_FIRST || slot == SLOTXY_INV_ROW3_FIRST || slot == SLOTXY_INV_ROW4_FIRST) { - slot += INV_ROW_SLOT_SIZE - icursW28; + if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { + if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) { + Slot += INV_ROW_SLOT_SIZE - icursW28; } else { - slot -= 1; + Slot -= 1; } - mousePos = InvGetSlotCoord(slot); - } else if (slot > SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) { - slot -= 1; - mousePos = BeltGetSlotCoord(slot); + mousePos = InvGetSlotCoord(Slot); + } else if (Slot > SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) { + Slot -= 1; + mousePos = BeltGetSlotCoord(Slot); } else if (myPlayer.HoldItem._itype == ITYPE_RING) { - slot = SLOTXY_RING_LEFT; + Slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { - if (slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_HAND_RIGHT_FIRST; + if (Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (slot == SLOTXY_HAND_RIGHT_FIRST) { - slot = SLOTXY_HAND_LEFT_FIRST; + } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) { + Slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); } } } else { - if (slot == SLOTXY_HAND_RIGHT_FIRST) { - slot = SLOTXY_CHEST_FIRST; + if (Slot == SLOTXY_HAND_RIGHT_FIRST) { + Slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); - } else if (slot == SLOTXY_CHEST_FIRST) { - slot = SLOTXY_HAND_LEFT_FIRST; + } else if (Slot == SLOTXY_CHEST_FIRST) { + Slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); - } else if (slot == SLOTXY_AMULET) { - slot = SLOTXY_HEAD_FIRST; + } else if (Slot == SLOTXY_AMULET) { + Slot = SLOTXY_HEAD_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); - } else if (slot == SLOTXY_RING_RIGHT) { - slot = SLOTXY_RING_LEFT; + } else if (Slot == SLOTXY_RING_RIGHT) { + Slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); - } else if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { - if (slot == SLOTXY_INV_ROW1_FIRST || slot == SLOTXY_INV_ROW2_FIRST || slot == SLOTXY_INV_ROW3_FIRST || slot == SLOTXY_INV_ROW4_FIRST) { - slot += INV_ROW_SLOT_SIZE - 1; + } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { + if (Slot == SLOTXY_INV_ROW1_FIRST || Slot == SLOTXY_INV_ROW2_FIRST || Slot == SLOTXY_INV_ROW3_FIRST || Slot == SLOTXY_INV_ROW4_FIRST) { + Slot += INV_ROW_SLOT_SIZE - 1; } else { - slot -= 1; + Slot -= 1; } - mousePos = InvGetSlotCoord(slot); - } else if (slot > SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) { - slot -= 1; - mousePos = BeltGetSlotCoord(slot); + mousePos = InvGetSlotCoord(Slot); + } else if (Slot > SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) { + Slot -= 1; + mousePos = BeltGetSlotCoord(Slot); } } } else if (dir.x == AxisDirectionX_RIGHT) { if (isHoldingItem) { - if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { + if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if ( - slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) { - slot -= INV_ROW_SLOT_SIZE - icursW28; + Slot == SLOTXY_INV_ROW1_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW2_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW3_LAST + 1 - icursW28 || Slot == SLOTXY_INV_ROW4_LAST + 1 - icursW28) { + Slot -= INV_ROW_SLOT_SIZE - icursW28; } else { - slot += 1; + Slot += 1; } - mousePos = InvGetSlotCoord(slot); - } else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { - slot += 1; - mousePos = BeltGetSlotCoord(slot); + mousePos = InvGetSlotCoord(Slot); + } else if (Slot >= SLOTXY_BELT_FIRST && Slot < SLOTXY_BELT_LAST) { + Slot += 1; + mousePos = BeltGetSlotCoord(Slot); } else if (myPlayer.HoldItem._itype == ITYPE_RING) { - slot = SLOTXY_RING_RIGHT; + Slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); } else if (myPlayer.HoldItem.isWeapon() || myPlayer.HoldItem.isShield()) { - if (slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_HAND_RIGHT_FIRST; + if (Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (slot == SLOTXY_HAND_RIGHT_FIRST) { - slot = SLOTXY_HAND_LEFT_FIRST; + } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) { + Slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); } } } else { - if (slot == SLOTXY_RING_LEFT) { - slot = SLOTXY_RING_RIGHT; + if (Slot == SLOTXY_RING_LEFT) { + Slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); - } else if (slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_CHEST_FIRST; + } else if (Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); - } else if (slot == SLOTXY_CHEST_FIRST) { - slot = SLOTXY_HAND_RIGHT_FIRST; + } else if (Slot == SLOTXY_CHEST_FIRST) { + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (slot == SLOTXY_HEAD_FIRST) { - slot = SLOTXY_AMULET; + } else if (Slot == SLOTXY_HEAD_FIRST) { + Slot = SLOTXY_AMULET; mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); - } else if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { + } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if ( - slot == SLOTXY_INV_ROW1_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW2_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW3_LAST + 1 - itemSize.width || slot == SLOTXY_INV_ROW4_LAST + 1 - itemSize.width) { - slot -= INV_ROW_SLOT_SIZE - itemSize.width; + Slot == SLOTXY_INV_ROW1_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW2_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW3_LAST + 1 - itemSize.width || Slot == SLOTXY_INV_ROW4_LAST + 1 - itemSize.width) { + Slot -= INV_ROW_SLOT_SIZE - itemSize.width; } else { - slot += itemSize.width; + Slot += itemSize.width; } - mousePos = InvGetSlotCoord(slot); - } else if (slot >= SLOTXY_BELT_FIRST && slot < SLOTXY_BELT_LAST) { - slot += 1; - mousePos = BeltGetSlotCoord(slot); + mousePos = InvGetSlotCoord(Slot); + } else if (Slot >= SLOTXY_BELT_FIRST && Slot < SLOTXY_BELT_LAST) { + Slot += 1; + mousePos = BeltGetSlotCoord(Slot); } } } if (dir.y == AxisDirectionY_UP) { if (isHoldingItem) { - if (slot >= SLOTXY_INV_ROW2_FIRST) { // general inventory - slot -= INV_ROW_SLOT_SIZE; - mousePos = InvGetSlotCoord(slot); - } else if (slot >= SLOTXY_INV_FIRST) { + if (Slot >= SLOTXY_INV_ROW2_FIRST) { // general inventory + Slot -= INV_ROW_SLOT_SIZE; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot >= SLOTXY_INV_FIRST) { if (myPlayer.HoldItem._itype == ITYPE_RING) { - if (slot >= SLOTXY_INV_ROW1_FIRST && slot <= SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2) - 1) { - slot = SLOTXY_RING_LEFT; + if (Slot >= SLOTXY_INV_ROW1_FIRST && Slot <= SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2) - 1) { + Slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); } else { - slot = SLOTXY_RING_RIGHT; + Slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); } } else if (myPlayer.HoldItem.isWeapon()) { - slot = SLOTXY_HAND_LEFT_FIRST; + Slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); } else if (myPlayer.HoldItem.isShield()) { - slot = SLOTXY_HAND_RIGHT_FIRST; + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); } else if (myPlayer.HoldItem.isHelm()) { - slot = SLOTXY_HEAD_FIRST; + Slot = SLOTXY_HEAD_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); } else if (myPlayer.HoldItem.isArmor()) { - slot = SLOTXY_CHEST_FIRST; + Slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); } else if (myPlayer.HoldItem._itype == ITYPE_AMULET) { - slot = SLOTXY_AMULET; + Slot = SLOTXY_AMULET; mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); } } } else { - if (slot >= SLOTXY_INV_ROW1_FIRST && slot < SLOTXY_INV_ROW1_FIRST + 3) { // first 3 general slots - slot = SLOTXY_RING_LEFT; + if (Slot >= SLOTXY_INV_ROW1_FIRST && Slot < SLOTXY_INV_ROW1_FIRST + 3) { // first 3 general slots + Slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); - } else if (slot >= SLOTXY_INV_ROW1_FIRST + 3 && slot < SLOTXY_INV_ROW1_FIRST + 7) { // middle 4 general slots - slot = SLOTXY_CHEST_FIRST; + } else if (Slot >= SLOTXY_INV_ROW1_FIRST + 3 && Slot < SLOTXY_INV_ROW1_FIRST + 7) { // middle 4 general slots + Slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); - } else if (slot >= SLOTXY_INV_ROW1_FIRST + 7 && slot < SLOTXY_INV_ROW1_LAST) { // last 3 general slots - slot = SLOTXY_RING_RIGHT; + } else if (Slot >= SLOTXY_INV_ROW1_FIRST + 7 && Slot < SLOTXY_INV_ROW1_LAST) { // last 3 general slots + Slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); - } else if (slot == SLOTXY_CHEST_FIRST || slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_HEAD_FIRST; + } else if (Slot == SLOTXY_CHEST_FIRST || Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_HEAD_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HEAD); - } else if (slot == SLOTXY_RING_LEFT) { - slot = SLOTXY_HAND_LEFT_FIRST; + } else if (Slot == SLOTXY_RING_LEFT) { + Slot = SLOTXY_HAND_LEFT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_LEFT); - } else if (slot == SLOTXY_RING_RIGHT) { - slot = SLOTXY_HAND_RIGHT_FIRST; + } else if (Slot == SLOTXY_RING_RIGHT) { + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (slot == SLOTXY_HAND_RIGHT_FIRST) { - slot = SLOTXY_AMULET; + } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) { + Slot = SLOTXY_AMULET; mousePos = InvGetEquipSlotCoord(INVLOC_AMULET); - } else if (slot >= SLOTXY_INV_ROW2_FIRST) { - slot -= INV_ROW_SLOT_SIZE; - mousePos = InvGetSlotCoord(slot); + } else if (Slot >= SLOTXY_INV_ROW2_FIRST) { + Slot -= INV_ROW_SLOT_SIZE; + mousePos = InvGetSlotCoord(Slot); } } } else if (dir.y == AxisDirectionY_DOWN) { if (isHoldingItem) { - if (slot == SLOTXY_HEAD_FIRST || slot == SLOTXY_CHEST_FIRST) { - slot = SLOTXY_INV_ROW1_FIRST + 4; - mousePos = InvGetSlotCoord(slot); - } else if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_INV_ROW1_FIRST + 1; - mousePos = InvGetSlotCoord(slot); - } else if (slot == SLOTXY_RING_RIGHT || slot == SLOTXY_HAND_RIGHT_FIRST || slot == SLOTXY_AMULET) { - slot = SLOTXY_INV_ROW1_LAST - 1; - mousePos = InvGetSlotCoord(slot); - } else if (slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) { - slot += INV_ROW_SLOT_SIZE; - mousePos = InvGetSlotCoord(slot); - } else if (slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items - slot += INV_ROW_SLOT_SIZE; - if (slot > SLOTXY_BELT_LAST) - slot = SLOTXY_BELT_LAST; - mousePos = BeltGetSlotCoord(slot); + if (Slot == SLOTXY_HEAD_FIRST || Slot == SLOTXY_CHEST_FIRST) { + Slot = SLOTXY_INV_ROW1_FIRST + 4; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot == SLOTXY_RING_LEFT || Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_INV_ROW1_FIRST + 1; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot == SLOTXY_RING_RIGHT || Slot == SLOTXY_HAND_RIGHT_FIRST || Slot == SLOTXY_AMULET) { + Slot = SLOTXY_INV_ROW1_LAST - 1; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (icursH28 * INV_ROW_SLOT_SIZE))) { + Slot += INV_ROW_SLOT_SIZE; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot <= SLOTXY_INV_LAST && myPlayer.HoldItem._itype == ITYPE_MISC && icursW28 == 1 && icursH28 == 1) { // forcing only 1x1 misc items + Slot += INV_ROW_SLOT_SIZE; + if (Slot > SLOTXY_BELT_LAST) + Slot = SLOTXY_BELT_LAST; + mousePos = BeltGetSlotCoord(Slot); } } else { - if (slot == SLOTXY_HEAD_FIRST) { - slot = SLOTXY_CHEST_FIRST; + if (Slot == SLOTXY_HEAD_FIRST) { + Slot = SLOTXY_CHEST_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_CHEST); - } else if (slot == SLOTXY_CHEST_FIRST) { - slot = SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2); - mousePos = InvGetSlotCoord(slot); - } else if (slot == SLOTXY_HAND_LEFT_FIRST) { - slot = SLOTXY_RING_LEFT; + } else if (Slot == SLOTXY_CHEST_FIRST) { + Slot = SLOTXY_INV_ROW1_FIRST + (INV_ROW_SLOT_SIZE / 2); + mousePos = InvGetSlotCoord(Slot); + } else if (Slot == SLOTXY_HAND_LEFT_FIRST) { + Slot = SLOTXY_RING_LEFT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_LEFT); - } else if (slot == SLOTXY_RING_LEFT) { - slot = SLOTXY_INV_ROW1_FIRST + 1; - mousePos = InvGetSlotCoord(slot); - } else if (slot == SLOTXY_RING_RIGHT) { - slot = SLOTXY_INV_ROW1_LAST - 1; - mousePos = InvGetSlotCoord(slot); - } else if (slot == SLOTXY_AMULET) { - slot = SLOTXY_HAND_RIGHT_FIRST; + } else if (Slot == SLOTXY_RING_LEFT) { + Slot = SLOTXY_INV_ROW1_FIRST + 1; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot == SLOTXY_RING_RIGHT) { + Slot = SLOTXY_INV_ROW1_LAST - 1; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot == SLOTXY_AMULET) { + Slot = SLOTXY_HAND_RIGHT_FIRST; mousePos = InvGetEquipSlotCoord(INVLOC_HAND_RIGHT); - } else if (slot == SLOTXY_HAND_RIGHT_FIRST) { - slot = SLOTXY_RING_RIGHT; + } else if (Slot == SLOTXY_HAND_RIGHT_FIRST) { + Slot = SLOTXY_RING_RIGHT; mousePos = InvGetEquipSlotCoord(INVLOC_RING_RIGHT); - } else if (slot <= (SLOTXY_INV_ROW4_LAST - (itemSize.height * INV_ROW_SLOT_SIZE))) { - slot += itemSize.height * INV_ROW_SLOT_SIZE; - mousePos = InvGetSlotCoord(slot); - } else if (slot <= SLOTXY_INV_LAST) { - slot += itemSize.height * INV_ROW_SLOT_SIZE; - if (slot > SLOTXY_BELT_LAST) - slot = SLOTXY_BELT_LAST; - mousePos = BeltGetSlotCoord(slot); + } else if (Slot <= (SLOTXY_INV_ROW4_LAST - (itemSize.height * INV_ROW_SLOT_SIZE))) { + Slot += itemSize.height * INV_ROW_SLOT_SIZE; + mousePos = InvGetSlotCoord(Slot); + } else if (Slot <= SLOTXY_INV_LAST) { + Slot += itemSize.height * INV_ROW_SLOT_SIZE; + if (Slot > SLOTXY_BELT_LAST) + Slot = SLOTXY_BELT_LAST; + mousePos = BeltGetSlotCoord(Slot); } } } // no movement was made - if (slot == initialSlot) + if (Slot == initialSlot) return; // get item under new slot if navigating on the inventory - if (!isHoldingItem && slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { - itemSize = GetItemSizeOnSlot(slot, itemInvId); + if (!isHoldingItem && Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { + itemSize = GetItemSizeOnSlot(Slot, itemInvId); // search the 'first slot' for that item in the inventory, it should have the positive number of that same InvId if (itemInvId < 0) { for (int s = 0; s < SLOTXY_INV_LAST - SLOTXY_INV_FIRST; ++s) { if (myPlayer.InvGrid[s] == -itemInvId) { - slot = SLOTXY_INV_FIRST + s; + Slot = SLOTXY_INV_FIRST + s; break; } } } // offset the slot to always move to the top-left most slot of that item - slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); - mousePos = InvGetSlotCoord(slot); + Slot -= ((itemSize.height - 1) * INV_ROW_SLOT_SIZE); + mousePos = InvGetSlotCoord(Slot); mousePos.x += ((itemSize.width - 1) * InventorySlotSizeInPixels.width) / 2; mousePos.y += ((itemSize.height - 1) * InventorySlotSizeInPixels.height) / 2; } // move cursor to the center of the slot if not holding anything or top left is holding an object if (isHoldingItem) { - if (slot >= SLOTXY_INV_FIRST) + if (Slot >= SLOTXY_INV_FIRST) mousePos.y -= InventorySlotSizeInPixels.height; else mousePos.y -= (int)((icursH28 / 2.0) * InventorySlotSizeInPixels.height) + (InventorySlotSizeInPixels.height / 2); @@ -1297,7 +1297,7 @@ void HandleRightStickMotion() */ void FocusOnInventory() { - slot = SLOTXY_INV_FIRST; + Slot = SLOTXY_INV_FIRST; ResetInvCursorPosition(); } diff --git a/Source/controls/touch.cpp b/Source/controls/touch.cpp index 676f86ae6..21b6abe1f 100644 --- a/Source/controls/touch.cpp +++ b/Source/controls/touch.cpp @@ -318,12 +318,12 @@ static void PreprocessFingerMotion(SDL_Event *event) devilution::OutputToLogical(&x, &y); } else { // for relative mode, use the pointer speed setting - constexpr float speedFactor = 1.25F; + constexpr float SpeedFactor = 1.25F; // convert touch events to relative mouse pointer events // Whenever an SDL_event involving the mouse is processed, - x = static_cast(mouse_x + (event->tfinger.dx * speedFactor * devilution::GetOutputSurface()->w)); - y = static_cast(mouse_y + (event->tfinger.dy * speedFactor * devilution::GetOutputSurface()->h)); + x = static_cast(mouse_x + (event->tfinger.dx * SpeedFactor * devilution::GetOutputSurface()->w)); + y = static_cast(mouse_y + (event->tfinger.dy * SpeedFactor * devilution::GetOutputSurface()->h)); } x = clip(x, 0, devilution::GetOutputSurface()->w); diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 4a819166c..c1d45b61b 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -973,7 +973,7 @@ static void PressKey(int vkey) if (sgnTimeoutCurs != CURSOR_NONE) { return; } - keymapper.keyPressed(vkey); + keymapper.KeyPressed(vkey); if (vkey == DVL_VK_RETURN) { if (GetAsyncKeyState(DVL_VK_MENU)) dx_reinit(); @@ -1005,7 +1005,7 @@ static void PressKey(int vkey) return; } - keymapper.keyPressed(vkey); + keymapper.KeyPressed(vkey); if (vkey == DVL_VK_RETURN) { if (GetAsyncKeyState(DVL_VK_MENU)) { @@ -1959,20 +1959,20 @@ bool isPlayerDead() void initKeymapActions() { - keymapper.addAction({ + keymapper.AddAction({ "Help", DVL_VK_F1, helpKeyPressed, [&]() { return !isPlayerDead(); }, }); #ifdef _DEBUG - keymapper.addAction({ + keymapper.AddAction({ "ItemInfo", DVL_VK_INVALID, itemInfoKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "QuestDebug", DVL_VK_INVALID, PrintDebugQuest, @@ -1980,7 +1980,7 @@ void initKeymapActions() }); #endif for (int i = 0; i < 4; ++i) { - quickSpellActionIndexes[i] = keymapper.addAction({ + quickSpellActionIndexes[i] = keymapper.AddAction({ std::string("QuickSpell") + std::to_string(i + 1), DVL_VK_F5 + i, [i]() { @@ -1994,43 +1994,43 @@ void initKeymapActions() }); } for (int i = 0; i < 4; ++i) { - keymapper.addAction({ + keymapper.AddAction({ QuickMessages[i].key, DVL_VK_F9 + i, [i]() { DiabloHotkeyMsg(i); }, }); } - keymapper.addAction({ + keymapper.AddAction({ "DecreaseGamma", 'G', DecreaseGamma, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "IncreaseGamma", 'F', IncreaseGamma, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "Inventory", 'I', inventoryKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "Character", 'C', characterSheetKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "QuestLog", 'Q', questLogKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "Zoom", 'Z', [] { @@ -2039,19 +2039,19 @@ void initKeymapActions() }, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "DisplaySpells", 'S', displaySpellsKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "SpellBook", 'B', spellBookKeyPressed, [&]() { return !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "GameInfo", 'V', [] { @@ -2061,13 +2061,16 @@ void initKeymapActions() _("Nightmare"), _("Hell"), }; - strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */ "{:s}, version = {:s}, mode = {:s}"), gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty]).c_str()); + strcpy(pszStr, fmt::format(_(/* TRANSLATORS: {:s} means: Character Name, Game Version, Game Difficulty. */ + "{:s}, version = {:s}, mode = {:s}"), + gszProductName, PROJECT_VERSION, difficulties[sgGameInitInfo.nDifficulty]) + .c_str()); NetSendCmdString(1 << MyPlayerId, pszStr); }, [&]() { return !isPlayerDead(); }, }); for (int i = 0; i < 8; ++i) { - keymapper.addAction({ + keymapper.AddAction({ std::string("BeltItem") + std::to_string(i + 1), '1' + i, [i] { @@ -2079,25 +2082,25 @@ void initKeymapActions() [&]() { return !isPlayerDead(); }, }); } - keymapper.addAction({ + keymapper.AddAction({ "QuickSave", DVL_VK_F2, [] { gamemenu_save_game(false); }, [&]() { return !gbIsMultiplayer && !isPlayerDead(); }, }); - keymapper.addAction({ + keymapper.AddAction({ "QuickLoad", DVL_VK_F3, [] { gamemenu_load_game(false); }, [&]() { return !gbIsMultiplayer && gbValidSaveFile; }, }); - keymapper.addAction({ + keymapper.AddAction({ "QuitGame", DVL_VK_INVALID, [] { gamemenu_quit_game(false); }, }); #ifdef _DEBUG - keymapper.addAction({ + keymapper.AddAction({ "CheatExperience", DVL_VK_INVALID, [] { @@ -2109,7 +2112,7 @@ void initKeymapActions() [&]() { return !isPlayerDead(); }, }); #endif - keymapper.addAction({ + keymapper.AddAction({ "StopHero", DVL_VK_INVALID, [] { Players[MyPlayerId].Stop(); }, diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index 2052b053c..f72662f4d 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -759,7 +759,7 @@ static void DrlgL1Shadows() } } -static int DrlgPlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int noquad, int ldir) +static int DrlgPlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int noquad) { int sx; int sy; @@ -2286,20 +2286,20 @@ static void DrlgL5(lvl_entry entry) if (QuestStatus(Q_PWATER)) { if (entry == ENTRY_MAIN) { - if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; } else { - if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, false, -1, 0) < 0) + if (DrlgPlaceMiniSet(PWATERIN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; ViewY--; } } if (QuestStatus(Q_LTBANNER)) { if (entry == ENTRY_MAIN) { - if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0) doneflag = false; } else { - if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) + if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0) doneflag = false; if (entry == ENTRY_PREV) { ViewX = 2 * setpc_x + 20; @@ -2311,49 +2311,49 @@ static void DrlgL5(lvl_entry entry) } else if (entry == ENTRY_MAIN) { if (currlevel < 21) { if (!Players[MyPlayerId].pOriginalCathedral) { - if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, true, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } else { - if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, true, -1) < 0) doneflag = false; - else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } } else if (currlevel == 21) { - if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1, 6) < 0) + if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; ViewY++; } else { - if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0) doneflag = false; if (currlevel != 24) { - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } ViewY++; } } else if (!Players[MyPlayerId].pOriginalCathedral && entry == ENTRY_PREV) { if (currlevel < 21) { - if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) + if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) + if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; ViewY--; } else if (currlevel == 21) { - if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1, 6) < 0) + if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; ViewY += 3; } else { - if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0) doneflag = false; if (currlevel != 24) { - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; } ViewY += 3; @@ -2361,27 +2361,27 @@ static void DrlgL5(lvl_entry entry) } else { if (currlevel < 21) { if (!Players[MyPlayerId].pOriginalCathedral) { - if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) + if (DrlgPlaceMiniSet(STAIRSUP, 1, 1, 0, 0, false, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } else { - if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, false, -1, 0) < 0) + if (DrlgPlaceMiniSet(L5STAIRSUP, 1, 1, 0, 0, false, -1) < 0) doneflag = false; - else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1, 1) < 0) + else if (DrlgPlaceMiniSet(STAIRSDOWN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; ViewY--; } } else if (currlevel == 21) { - if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, true, -1, 6) < 0) + if (DrlgPlaceMiniSet(L5STAIRSTOWN, 1, 1, 0, 0, true, -1) < 0) doneflag = false; - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } else { - if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1, 0) < 0) + if (DrlgPlaceMiniSet(L5STAIRSUPHF, 1, 1, 0, 0, true, -1) < 0) doneflag = false; if (currlevel != 24) { - if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1, 1) < 0) + if (DrlgPlaceMiniSet(L5STAIRSDOWN, 1, 1, 0, 0, false, -1) < 0) doneflag = false; } } @@ -2462,7 +2462,7 @@ static void DrlgL5(lvl_entry entry) if (currlevel < 21) { DrlgL1Shadows(); - DrlgPlaceMiniSet(LAMPS, 5, 10, 0, 0, false, -1, 4); + DrlgPlaceMiniSet(LAMPS, 5, 10, 0, 0, false, -1); DrlgL1Floor(); } diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index ccb11ee8a..f690ece9c 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1612,7 +1612,7 @@ int Patterns[100][10] = { } // namespace -static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL2PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview) { int sw = miniset[0]; int sh = miniset[1]; @@ -1775,7 +1775,7 @@ static void DrlgL2Subs() static void DrlgL2Shadows() { - int8_t sd[2][2]; + uint8_t sd[2][2]; for (int y = 1; y < DMAXY; y++) { for (int x = 1; x < DMAXX; x++) { @@ -2965,29 +2965,29 @@ static void DrlgL2(lvl_entry entry) DrlgL2FloodTVal(); DrlgL2TransFix(); if (entry == ENTRY_MAIN) { - doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, true); if (doneflag) { - doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel == 5) { - doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false); } } ViewY -= 2; } else if (entry == ENTRY_PREV) { - doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false); if (doneflag) { - doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, true); if (doneflag && currlevel == 5) { - doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, false); } } ViewX--; } else { - doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL2PlaceMiniSet(USTAIRS, 1, 1, -1, -1, false); if (doneflag) { - doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL2PlaceMiniSet(DSTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel == 5) { - doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true, 6); + doneflag = DrlgL2PlaceMiniSet(WARPSTAIRS, 1, 1, -1, -1, true); } } ViewY -= 2; diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index 18e936899..261bd1de8 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -1598,7 +1598,7 @@ static void DrlgL3PoolFix() } } -static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL3PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview) { int sx; int sy; @@ -2257,67 +2257,67 @@ static void DrlgL3(lvl_entry entry) DrlgL3MakeMegas(); if (entry == ENTRY_MAIN) { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, true, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, true); } else { if (currlevel != 17) - genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, true, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, true); else - genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true); } if (!genok) { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false); } else { if (currlevel != 20) - genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false); } if (!genok && currlevel == 9) { - genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false); } } } else if (entry == ENTRY_PREV) { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false); } else { if (currlevel != 17) - genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false); else - genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, false); } if (!genok) { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, true); ViewX += 2; ViewY -= 2; } else { if (currlevel != 20) { - genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, true); ViewX += 2; ViewY -= 2; } } if (!genok && currlevel == 9) { - genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, false); } } } else { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L3UP, 1, 1, -1, -1, false); } else { if (currlevel != 17) - genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false, 0); + genok = DrlgL3PlaceMiniSet(L6UP, 1, 1, -1, -1, false); else - genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L6HOLDWARP, 1, 1, -1, -1, true); } if (!genok) { if (currlevel < 17) { - genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L3DOWN, 1, 1, -1, -1, false); } else { if (currlevel != 20) - genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false, 1); + genok = DrlgL3PlaceMiniSet(L6DOWN, 1, 1, -1, -1, false); } if (!genok && currlevel == 9) { - genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true, 6); + genok = DrlgL3PlaceMiniSet(L3HOLDWARP, 1, 1, -1, -1, true); } } } @@ -2494,9 +2494,7 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry) DoLighting({ i, j }, 7, -1); } else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) { DoLighting({ i, j }, 7, -1); - } else if (dPiece[i][j] == 150) { - DoLighting({ i, j }, 7, -1); - } else if (dPiece[i][j] == 152) { + } else if (IsAnyOf(dPiece[i][j], 150, 152)) { DoLighting({ i, j }, 7, -1); } } diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index 3c2c56350..dcdc0b1e0 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1094,7 +1094,7 @@ void DRLG_LoadDiabQuads(bool preflag) } } -static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview, int ldir) +static bool DrlgL4PlaceMiniSet(const BYTE *miniset, int tmin, int tmax, int cx, int cy, bool setview) { int sx; int sy; @@ -1393,72 +1393,72 @@ static void DrlgL4(lvl_entry entry) } if (QuestStatus(Q_WARLORD)) { if (entry == ENTRY_MAIN) { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true); if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false); } ViewX++; } else if (entry == ENTRY_PREV) { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false); } ViewX = 2 * setpc_x + 22; ViewY = 2 * setpc_y + 22; } else { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true); } ViewX++; } } else if (currlevel != 15) { if (entry == ENTRY_MAIN) { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true); if (doneflag && currlevel != 16) { - doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false); } if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false); } ViewX++; } else if (entry == ENTRY_PREV) { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel != 16) { - doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, true); } if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, false); } ViewY++; } else { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false); if (doneflag && currlevel != 16) { - doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4DSTAIRS, 1, 1, -1, -1, false); } if (doneflag && currlevel == 13) { - doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true, 6); + doneflag = DrlgL4PlaceMiniSet(L4TWARP, 1, 1, -1, -1, true); } ViewX++; } } else { if (entry == ENTRY_MAIN) { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, true); if (doneflag) { if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { - doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, false); } else { - doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, false); } } ViewX++; } else { - doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false, 0); + doneflag = DrlgL4PlaceMiniSet(L4USTAIRS, 1, 1, -1, -1, false); if (doneflag) { if (!gbIsMultiplayer && Quests[Q_DIABLO]._qactive != QUEST_ACTIVE) { - doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA, 1, 1, -1, -1, true); } else { - doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true, 1); + doneflag = DrlgL4PlaceMiniSet(L4PENTA2, 1, 1, -1, -1, true); } } ViewY++; diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 1030c2255..67c878655 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -107,8 +107,8 @@ static void GmenuLeftRight(bool isRight) if ((sgpCurrItem->dwFlags & GMENU_SLIDER) == 0) return; - int step = sgpCurrItem->dwFlags & 0xFFF; - int steps = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12; + uint16_t step = sgpCurrItem->dwFlags & 0xFFF; + uint16_t steps = (sgpCurrItem->dwFlags & 0xFFF000) >> 12; if (isRight) { if (step == steps) return; @@ -166,9 +166,9 @@ static void GmenuDrawMenuItem(const Surface &out, TMenuItem *pItem, int y) if ((pItem->dwFlags & GMENU_SLIDER) != 0) { int x = 16 + w / 2; CelDrawTo(out, { x + PANEL_LEFT, y - 10 }, *optbar_cel, 1); - int step = pItem->dwFlags & 0xFFF; - int nSteps = std::max((pItem->dwFlags & 0xFFF000) >> 12, 2); - int pos = step * 256 / nSteps; + uint16_t step = pItem->dwFlags & 0xFFF; + uint16_t steps = std::max((pItem->dwFlags & 0xFFF000) >> 12, 2); + uint16_t pos = step * 256 / steps; GmenuClearBuffer(out, x + 2 + PANEL_LEFT, y - 12, pos + 13, 28); CelDrawTo(out, { x + 2 + pos + PANEL_LEFT, y - 12 }, *option_cel, 1); } @@ -280,7 +280,7 @@ bool gmenu_on_mouse_move() if (!mouseNavigation) return false; - int step = (int)(sgpCurrItem->dwFlags & 0xFFF000) >> 12; + uint16_t step = (sgpCurrItem->dwFlags & 0xFFF000) >> 12; step *= GmenuGetMouseSlider(); step /= 256; @@ -350,7 +350,7 @@ void gmenu_enable(TMenuItem *pMenuItem, bool enable) void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value) { assert(pItem); - int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2); + uint16_t nSteps = std::max((pItem->dwFlags & 0xFFF000) >> 12, 2); pItem->dwFlags &= 0xFFFFF000; pItem->dwFlags |= ((max - min - 1) / 2 + (value - min) * nSteps) / (max - min); } @@ -360,9 +360,9 @@ void gmenu_slider_set(TMenuItem *pItem, int min, int max, int value) */ int gmenu_slider_get(TMenuItem *pItem, int min, int max) { - int step = pItem->dwFlags & 0xFFF; - int nSteps = std::max((int)(pItem->dwFlags & 0xFFF000) >> 12, 2); - return min + (step * (max - min) + (nSteps - 1) / 2) / nSteps; + uint16_t step = pItem->dwFlags & 0xFFF; + uint16_t steps = std::max((pItem->dwFlags & 0xFFF000) >> 12, 2); + return min + (step * (max - min) + (steps - 1) / 2) / steps; } /** diff --git a/Source/help.cpp b/Source/help.cpp index 4b556bf7f..ec99cb2fb 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -96,13 +96,13 @@ std::vector HelpTextLines; void InitHelp() { HelpFlag = false; - char tempstr[512]; + char tempString[512]; for (const auto *text : HelpText) { - strcpy(tempstr, _(text)); + strcpy(tempString, _(text)); - WordWrapGameString(tempstr, 577); - const string_view paragraph = tempstr; + WordWrapGameString(tempString, 577); + const string_view paragraph = tempString; size_t previous = 0; while (true) { diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 6c2080415..258394fd1 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -79,7 +79,7 @@ static Cutscenes PickCutscene(interface_mode uMsg) default: return CutLevel1; } - }; + } case WM_DIABWARPLVL: return CutPortal; case WM_DIABSETLVL: diff --git a/Source/items.cpp b/Source/items.cpp index a69a4da01..517440569 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1706,6 +1706,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi r2 = RndPL(51, 75); if (param1 == 151) r2 = RndPL(76, 100); + Items[i]._iPLToHit += r2; break; case IPL_TOHIT_DAMP_CURSE: @@ -1714,6 +1715,7 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi r2 = RndPL(1, 5); if (param1 == 50) r2 = RndPL(6, 10); + Items[i]._iPLToHit -= r2; break; case IPL_ACP: @@ -1994,7 +1996,6 @@ void SaveItemPower(int i, item_effect_type power, int param1, int param2, int mi case IPL_FIRERESCLVL: Items[i]._iPLFR = 30 - Players[MyPlayerId]._pLevel; Items[i]._iPLFR = std::max(Items[i]._iPLFR, 0); - break; case IPL_FIRERES_CURSE: Items[i]._iPLFR -= r; diff --git a/Source/lighting.cpp b/Source/lighting.cpp index ff559c196..6d24f5de1 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -416,10 +416,10 @@ const char CrawlTable[2749] = { }; /* - * VisionCrawlTable specifies the X- Y-coordinate offsets of lighting visions. - * The last entry-pair is only for alignment. + * X- Y-coordinate offsets of lighting visions. + * The last entry-pair is only for alignment. */ -const BYTE VisionCrawlTable[23][30] = { +const uint8_t VisionCrawlTable[23][30] = { // clang-format off { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 }, { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 }, diff --git a/Source/monster.cpp b/Source/monster.cpp index 04c2b91d0..6317e2076 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -204,21 +204,19 @@ void InitMonsterTRN(CMonster &monst) void InitLevelMonsters() { - int i; - LevelMonsterTypeCount = 0; monstimgtot = 0; MissileFileFlag = 0; - for (i = 0; i < MAX_LVLMTYPES; i++) { - LevelMonsterTypes[i].mPlaceFlags = 0; + for (auto &levelMonsterType : LevelMonsterTypes) { + levelMonsterType.mPlaceFlags = 0; } ClrAllMonsters(); ActiveMonsterCount = 0; totalmonsters = MAXMONSTERS; - for (i = 0; i < MAXMONSTERS; i++) { + for (int i = 0; i < MAXMONSTERS; i++) { ActiveMonsters[i] = i; } @@ -2347,7 +2345,7 @@ bool M_DoTalk(int i) MonsterStruct *monst = &Monsters[i]; M_StartStand(i, Monsters[i]._mdir); - monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of Monsters[i] in the rest of the function + monst->_mgoal = MGOAL_TALKING; // CODEFIX: apply Monst instead of monster[i] in the rest of the function if (effect_is_playing(Texts[Monsters[i].mtalkmsg].sfxnr)) return false; InitQTextMsg(Monsters[i].mtalkmsg); diff --git a/Source/nthread.h b/Source/nthread.h index 49376a53f..7e5434c78 100644 --- a/Source/nthread.h +++ b/Source/nthread.h @@ -20,10 +20,10 @@ extern DWORD gdwNormalMsgSize; extern float gfProgressToNextGameTick; // the progress as a fraction (0.0f to 1.0f) in time to the next game tick void nthread_terminate_game(const char *pszFcn); -DWORD nthread_send_and_recv_turn(DWORD cur_turn, int turn_delta); +DWORD nthread_send_and_recv_turn(DWORD curTurn, int turnDelta); bool nthread_recv_turns(bool *pfSendAsync = nullptr); void nthread_set_turn_upper_bit(); -void nthread_start(bool set_turn_upper_bit); +void nthread_start(bool setTurnUpperBit); void nthread_cleanup(); void nthread_ignore_mutex(bool bStart); bool nthread_has_500ms_passed(); diff --git a/Source/options.cpp b/Source/options.cpp index 266ec9cf8..88311332b 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -214,7 +214,7 @@ void LoadOptions() GetIniValue("Language", "Code", sgOptions.Language.szCode, sizeof(sgOptions.Language.szCode), "en"); - keymapper.load(); + keymapper.Load(); sbWasOptionsLoaded = true; } @@ -298,7 +298,7 @@ void SaveOptions() SetIniValue("Language", "Code", sgOptions.Language.szCode); - keymapper.save(); + keymapper.Save(); SaveIni(); } diff --git a/Source/path.cpp b/Source/path.cpp index ece8b7d48..66b6066a2 100644 --- a/Source/path.cpp +++ b/Source/path.cpp @@ -30,8 +30,18 @@ PATHNODE *pnode_tblptr[MAXPATHNODES]; PATHNODE *path_2_nodes; /** For iterating over the 8 possible movement directions */ -const char pathxdir[8] = { -1, -1, 1, 1, -1, 0, 1, 0 }; -const char pathydir[8] = { -1, 1, -1, 1, 0, -1, 0, 1 }; +const Displacement PathDirs[8] = { + // clang-format off + { -1, -1 }, + { -1, 1 }, + { 1, -1 }, + { 1, 1 }, + { -1, 0 }, + { 0, -1 }, + { 1, 0 }, + { 0, 1 }, + // clang-format on +}; /* data */ @@ -179,12 +189,11 @@ bool path_solid_pieces(PATHNODE *pPath, int dx, int dy) */ bool path_get_path(bool (*posOk)(int, Point), int posOkArg, PATHNODE *pPath, int x, int y) { - for (int i = 0; i < 8; i++) { - int dx = pPath->position.x + pathxdir[i]; - int dy = pPath->position.y + pathydir[i]; - bool ok = posOk(posOkArg, { dx, dy }); - if ((ok && path_solid_pieces(pPath, dx, dy)) || (!ok && dx == x && dy == y)) { - if (!path_parent_path(pPath, dx, dy, x, y)) + for (auto dir : PathDirs) { + Point tile = pPath->position + dir; + bool ok = posOk(posOkArg, tile); + if ((ok && path_solid_pieces(pPath, tile.x, tile.y)) || (!ok && tile == Point { x, y })) { + if (!path_parent_path(pPath, tile.x, tile.y, x, y)) return false; } } diff --git a/Source/path.h b/Source/path.h index 06cc17a9d..cad9a0e73 100644 --- a/Source/path.h +++ b/Source/path.h @@ -7,6 +7,7 @@ #include +#include "engine/direction.hpp" #include "engine/point.hpp" namespace devilution { @@ -39,7 +40,6 @@ PATHNODE *path_new_step(); /* rdata */ -extern const char pathxdir[8]; -extern const char pathydir[8]; +extern const Displacement PathDirs[8]; } // namespace devilution diff --git a/Source/player.cpp b/Source/player.cpp index 84680c116..d53c51897 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1677,11 +1677,11 @@ static void PlrDeadItem(PlayerStruct &player, ItemStruct *itm, Displacement dire for (int k = 1; k < 50; k++) { for (int j = -k; j <= k; j++) { for (int i = -k; i <= k; i++) { - Point target = player.position.tile + Displacement { i, j }; - if (ItemSpaceOk(target)) { - RespawnDeadItem(itm, target); + Point next = player.position.tile + Displacement { i, j }; + if (ItemSpaceOk(next)) { + RespawnDeadItem(itm, next); player.HoldItem = *itm; - NetSendCmdPItem(false, CMD_RESPAWNITEM, target); + NetSendCmdPItem(false, CMD_RESPAWNITEM, next); return; } } diff --git a/Source/qol/autopickup.cpp b/Source/qol/autopickup.cpp index 25c86227c..d2464da07 100644 --- a/Source/qol/autopickup.cpp +++ b/Source/qol/autopickup.cpp @@ -44,11 +44,10 @@ void AutoGoldPickup(int pnum) if (!HasRoomForGold()) return; - for (int dir = 0; dir < 8; dir++) { - int x = Players[pnum].position.tile.x + pathxdir[dir]; - int y = Players[pnum].position.tile.y + pathydir[dir]; - if (dItem[x][y] != 0) { - int itemIndex = dItem[x][y] - 1; + for (auto pathDir : PathDirs) { + Point tile = Players[pnum].position.tile + pathDir; + if (dItem[tile.x][tile.y] != 0) { + int itemIndex = dItem[tile.x][tile.y] - 1; if (Items[itemIndex]._itype == ITYPE_GOLD) { NetSendCmdGItem(true, CMD_REQUESTAGITEM, pnum, pnum, itemIndex); Items[itemIndex]._iRequest = true; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 4ef267c21..7cd9f7e79 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -207,7 +207,6 @@ uint32_t sgdwCursHgtOld; bool dRendered[MAXDUNX][MAXDUNY]; -int frames; bool frameflag; int frameend; int framerate; @@ -452,8 +451,7 @@ static void DrawMonster(const Surface &out, int x, int y, int mx, int my, int m) Cl2DrawLightTbl(out, mx, my, cel, nCel, 1); return; } - - char trans = 0; + int trans = 0; if (Monsters[m]._uniqtype != 0) trans = Monsters[m]._uniqtrans + 4; if (Monsters[m]._mmode == MM_STONE) @@ -612,20 +610,20 @@ void DrawDeadPlayer(const Surface &out, int x, int y, int sx, int sy) */ static void DrawObject(const Surface &out, int x, int y, int ox, int oy, bool pre) { - if (dObject[x][y] == 0 || LightTableIndex >= LightsMax) + int8_t bv = dObject[x][y]; + if (bv == 0 || LightTableIndex >= LightsMax) return; Point objectPosition {}; - int8_t bv = -1; - if (dObject[x][y] > 0) { - bv = dObject[x][y] - 1; + if (bv > 0) { + bv = bv - 1; if (Objects[bv]._oPreFlag != pre) return; objectPosition.x = ox - CalculateWidth2(Objects[bv]._oAnimWidth); objectPosition.y = oy; } else { - bv = -(dObject[x][y] + 1); + bv = -(bv + 1); if (Objects[bv]._oPreFlag != pre) return; int xx = Objects[bv].position.x - x; @@ -827,7 +825,7 @@ static void DrawMonsterHelper(const Surface &out, int x, int y, int oy, int sx, */ static void DrawPlayerHelper(const Surface &out, int x, int y, int sx, int sy) { - int p = dPlayer[x][y]; + int8_t p = dPlayer[x][y]; p = p > 0 ? p - 1 : -(p + 1); if (p < 0 || p >= MAX_PLRS) { diff --git a/Source/setmaps.cpp b/Source/setmaps.cpp index bdcecde04..bf673658f 100644 --- a/Source/setmaps.cpp +++ b/Source/setmaps.cpp @@ -73,7 +73,7 @@ BYTE SkelChamTrans3[] = { }; /** Maps from quest level to quest level names. */ -const char *const quest_level_names[] = { +const char *const QuestLevelNames[] = { "", N_("Skeleton King's Lair"), N_("Chamber of Bone"), diff --git a/Source/setmaps.h b/Source/setmaps.h index 7016cbc25..7fb41844b 100644 --- a/Source/setmaps.h +++ b/Source/setmaps.h @@ -11,6 +11,6 @@ int ObjIndex(int x, int y); void LoadSetMap(); /* rdata */ -extern const char *const quest_level_names[]; +extern const char *const QuestLevelNames[]; } // namespace devilution diff --git a/Source/sound.cpp b/Source/sound.cpp index 1f203bcc6..2303b245e 100644 --- a/Source/sound.cpp +++ b/Source/sound.cpp @@ -161,7 +161,6 @@ void snd_play_snd(TSnd *pSnd, int lVolume, int lPan) std::unique_ptr sound_file_load(const char *path, bool stream) { - int error = 0; auto snd = std::make_unique(); snd->start_tc = SDL_GetTicks() - 80 - 1; @@ -169,8 +168,7 @@ std::unique_ptr sound_file_load(const char *path, bool stream) #ifndef STREAM_ALL_AUDIO if (stream) { #endif - error = snd->DSB.SetChunkStream(path); - if (error != 0) { + if (snd->DSB.SetChunkStream(path) != 0) { ErrSdl(); } #ifndef STREAM_ALL_AUDIO @@ -182,13 +180,13 @@ std::unique_ptr sound_file_load(const char *path, bool stream) DWORD dwBytes = SFileGetFileSize(file); auto waveFile = MakeArraySharedPtr(dwBytes); SFileReadFileThreadSafe(file, waveFile.get(), dwBytes); - error = snd->DSB.SetChunk(waveFile, dwBytes); + int error = snd->DSB.SetChunk(waveFile, dwBytes); SFileCloseFileThreadSafe(file); + if (error != 0) { + ErrSdl(); + } } #endif - if (error != 0) { - ErrSdl(); - } return snd; } diff --git a/Source/stores.cpp b/Source/stores.cpp index ee4b8d53c..f0be1650a 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -408,7 +408,7 @@ void ScrollSmithSell(int idx) void StartSmithSell() { stextsize = true; - bool sellok = false; + bool sellOk = false; storenumh = 0; for (auto &item : storehold) { @@ -417,11 +417,11 @@ void StartSmithSell() const auto &myPlayer = Players[MyPlayerId]; - for (int i = 0; i < myPlayer._pNumInv; i++) { + for (int8_t i = 0; i < myPlayer._pNumInv; i++) { if (storenumh >= 48) break; if (SmithSellOk(i)) { - sellok = true; + sellOk = true; storehold[storenumh] = myPlayer.InvList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) @@ -438,7 +438,7 @@ void StartSmithSell() if (storenumh >= 48) break; if (SmithSellOk(-(i + 1))) { - sellok = true; + sellOk = true; storehold[storenumh] = myPlayer.SpdList[i]; if (storehold[storenumh]._iMagical != ITEM_QUALITY_NORMAL && storehold[storenumh]._iIdentified) @@ -451,7 +451,7 @@ void StartSmithSell() } } - if (!sellok) { + if (!sellOk) { stextscrl = false; /* TRANSLATORS: This text is white space sensitive. Check for correct alignment! */ @@ -771,7 +771,7 @@ bool WitchRechargeOk(int i) return false; } -void AddStoreHoldRecharge(ItemStruct itm, int i) +void AddStoreHoldRecharge(ItemStruct itm, int8_t i) { storehold[storenumh] = itm; storehold[storenumh]._ivalue += spelldata[itm._iSpell].sStaffCost; @@ -1060,7 +1060,7 @@ bool IdItemOk(ItemStruct *i) return !i->_iIdentified; } -void AddStoreHoldId(ItemStruct itm, int i) +void AddStoreHoldId(ItemStruct itm, int8_t i) { storehold[storenumh] = itm; storehold[storenumh]._ivalue = 100; @@ -1549,7 +1549,7 @@ void SmithRepairItem() int idx = stextvhold + ((stextlhold - stextup) / 4); storehold[idx]._iDurability = storehold[idx]._iMaxDur; - int i = storehidx[idx]; + int8_t i = storehidx[idx]; if (i < 0) { if (i == -1) @@ -1709,7 +1709,7 @@ void WitchRechargeItem() int idx = stextvhold + ((stextlhold - stextup) / 4); storehold[idx]._iCharges = storehold[idx]._iMaxCharges; - int i = storehidx[idx]; + int8_t i = storehidx[idx]; if (i < 0) myPlayer.InvBody[INVLOC_HAND_LEFT]._iCharges = myPlayer.InvBody[INVLOC_HAND_LEFT]._iMaxCharges; else @@ -1863,7 +1863,7 @@ void StorytellerIdentifyItem() { auto &myPlayer = Players[MyPlayerId]; - int idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; + int8_t idx = storehidx[((stextlhold - stextup) / 4) + stextvhold]; if (idx < 0) { if (idx == -1) myPlayer.InvBody[INVLOC_HEAD]._iIdentified = true; @@ -2169,7 +2169,7 @@ ItemStruct witchitem[WITCH_ITEMS]; int boylevel; ItemStruct boyitem; -void AddStoreHoldRepair(ItemStruct *itm, int i) +void AddStoreHoldRepair(ItemStruct *itm, int8_t i) { ItemStruct *item; int v; diff --git a/Source/stores.h b/Source/stores.h index a067d1193..c3f5e5015 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -94,7 +94,7 @@ extern int boylevel; /** Current item sold by Wirt */ extern ItemStruct boyitem; -void AddStoreHoldRepair(ItemStruct *itm, int i); +void AddStoreHoldRepair(ItemStruct *itm, int8_t i); void InitStores(); void SetupTownStores(); void FreeStoreMem(); diff --git a/Source/utils/soundsample.cpp b/Source/utils/soundsample.cpp index 1f1269daa..241c56f38 100644 --- a/Source/utils/soundsample.cpp +++ b/Source/utils/soundsample.cpp @@ -74,7 +74,7 @@ void SoundSample::Release() file_data_ = nullptr; file_data_size_ = 0; #endif -}; +} /** * @brief Check if a the sound is being played atm @@ -82,7 +82,7 @@ void SoundSample::Release() bool SoundSample::IsPlaying() { return stream_ && stream_->isPlaying(); -}; +} /** * @brief Start playing the sound @@ -103,7 +103,7 @@ void SoundSample::Play(int logSoundVolume, int logUserVolume, int logPan) LogError(LogCategory::Audio, "Aulib::Stream::play (from SoundSample::Play): {}", SDL_GetError()); return; } -}; +} /** * @brief Stop playing the sound @@ -112,7 +112,7 @@ void SoundSample::Stop() { if (stream_) stream_->stop(); -}; +} int SoundSample::SetChunkStream(std::string filePath) { @@ -153,7 +153,7 @@ int SoundSample::SetChunk(ArraySharedPtr fileData, std::size_t dwB } return 0; -}; +} #endif /** @@ -164,6 +164,6 @@ int SoundSample::GetLength() const if (!stream_) return 0; return std::chrono::duration_cast(stream_->duration()).count(); -}; +} } // namespace devilution