diff --git a/Source/automap.cpp b/Source/automap.cpp index e1039c050..be328e742 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -145,10 +145,10 @@ struct AutomapTile { } template - [[nodiscard]] DVL_ALWAYS_INLINE constexpr bool hasAnyFlag(Flags flag, Args... flags) + [[nodiscard]] DVL_ALWAYS_INLINE constexpr bool hasAnyFlag(Flags flag, Args... testFlags) { return (static_cast(this->flags) - & (static_cast(flag) | ... | static_cast(flags))) + & (static_cast(flag) | ... | static_cast(testFlags))) != 0; } }; diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 40fc7145e..28ed8d36f 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -91,15 +91,15 @@ const Direction FaceDir[3][3] = { */ int GetRotaryDistance(Point destination) { - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; if (myPlayer.position.future == destination) return -1; - int d1 = static_cast(myPlayer._pdir); - int d2 = static_cast(GetDirection(myPlayer.position.future, destination)); + const int d1 = static_cast(myPlayer._pdir); + const int d2 = static_cast(GetDirection(myPlayer.position.future, destination)); - int d = std::abs(d1 - d2); + const int d = std::abs(d1 - d2); if (d > 4) return 4 - (d % 4); @@ -129,7 +129,7 @@ int GetDistance(Point destination, int maxDistance) int8_t walkpath[MaxPathLengthPlayer]; Player &myPlayer = *MyPlayer; - int steps = FindPath(CanStep, [&myPlayer](Point position) { return PosOkPlayer(myPlayer, position); }, myPlayer.position.future, destination, walkpath, std::min(maxDistance, MaxPathLengthPlayer)); + const int steps = FindPath(CanStep, [&myPlayer](Point position) { return PosOkPlayer(myPlayer, position); }, myPlayer.position.future, destination, walkpath, std::min(maxDistance, MaxPathLengthPlayer)); if (steps > maxDistance) return 0; @@ -147,25 +147,25 @@ int GetDistanceRanged(Point destination) void FindItemOrObject() { - WorldTilePosition futurePosition = MyPlayer->position.future; + const WorldTilePosition futurePosition = MyPlayer->position.future; int rotations = 5; auto searchArea = PointsInRectangleColMajor(WorldTileRectangle { futurePosition, 1 }); - for (WorldTilePosition targetPosition : searchArea) { + for (const WorldTilePosition targetPosition : searchArea) { // As the player can not stand on the edge of the map this is safe from OOB - int8_t itemId = dItem[targetPosition.x][targetPosition.y] - 1; + const int8_t itemId = dItem[targetPosition.x][targetPosition.y] - 1; if (itemId < 0) { // there shouldn't be any items that occupy multiple ground tiles, but just in case only considering positive indexes here continue; } - Item &item = Items[itemId]; + const Item &item = Items[itemId]; if (item.isEmpty() || item.selectionRegion == SelectionRegion::None) { continue; } - int newRotations = GetRotaryDistance(targetPosition); + const int newRotations = GetRotaryDistance(targetPosition); if (rotations < newRotations) { continue; } @@ -182,7 +182,7 @@ void FindItemOrObject() return; // Don't look for objects in town } - for (WorldTilePosition targetPosition : searchArea) { + for (const WorldTilePosition targetPosition : searchArea) { Object *object = FindObjectAtPosition(targetPosition); if (object == nullptr || !object->canInteractWith()) { // No object or non-interactive object @@ -192,7 +192,7 @@ void FindItemOrObject() continue; // Ignore doorway so we don't get stuck behind barrels } - int newRotations = GetRotaryDistance(targetPosition); + const int newRotations = GetRotaryDistance(targetPosition); if (rotations < newRotations) { continue; } @@ -213,7 +213,7 @@ void FindItemOrObject() void CheckTownersNearby() { for (int i = 0; i < 16; i++) { - int distance = GetDistance(Towners[i].position, 2); + const int distance = GetDistance(Towners[i].position, 2); if (distance == 0) continue; if (!IsTownerPresent(Towners[i]._ttype)) @@ -224,7 +224,7 @@ void CheckTownersNearby() bool HasRangedSpell() { - SpellID spl = MyPlayer->_pRSpell; + const SpellID spl = MyPlayer->_pRSpell; return spl != SpellID::Invalid && spl != SpellID::TownPortal @@ -260,7 +260,7 @@ void FindRangedTarget() bool canTalk = false; for (size_t i = 0; i < ActiveMonsterCount; i++) { - int mi = ActiveMonsters[i]; + const int mi = ActiveMonsters[i]; const Monster &monster = Monsters[mi]; if (!CanTargetMonster(monster)) @@ -297,7 +297,7 @@ void FindMeleeTarget() }; std::list queue; - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; { const int startX = myPlayer.position.future.x; @@ -307,7 +307,7 @@ void FindMeleeTarget() } while (!queue.empty()) { - SearchNode node = queue.front(); + const SearchNode node = queue.front(); queue.pop_front(); for (auto pathDir : PathDirs) { @@ -373,9 +373,9 @@ void CheckPlayerNearby() if (pcursmonst != -1) return; - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; - SpellID spl = myPlayer._pRSpell; + const SpellID spl = myPlayer._pRSpell; if (myPlayer.friendlyMode && spl != SpellID::Resurrect && spl != SpellID::HealOther) return; @@ -447,7 +447,7 @@ void FindTrigger() if (pcursmissile == nullptr) { for (int i = 0; i < numtrigs; i++) { - int tx = trigs[i].position.x; + const int tx = trigs[i].position.x; int ty = trigs[i].position.y; if (trigs[i]._tlvl == 13) ty -= 1; @@ -482,7 +482,7 @@ void FindTrigger() bool IsStandingGround() { if (ControlMode == ControlTypes::Gamepad) { - ControllerButtonCombo standGroundCombo = GetOptions().Padmapper.ButtonComboForAction("StandGround"); + const ControllerButtonCombo standGroundCombo = GetOptions().Padmapper.ButtonComboForAction("StandGround"); return StandToggle || IsControllerButtonComboPressed(standGroundCombo); } #ifndef USE_SDL1 @@ -500,12 +500,12 @@ void Interact() return; } - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; if (leveltype != DTYPE_TOWN && IsStandingGround()) { Direction pdir = myPlayer._pdir; - AxisDirection moveDir = GetMoveDirection(); - bool motion = moveDir.x != AxisDirectionX_NONE || moveDir.y != AxisDirectionY_NONE; + const AxisDirection moveDir = GetMoveDirection(); + const bool motion = moveDir.x != AxisDirectionX_NONE || moveDir.y != AxisDirectionY_NONE; if (motion) { pdir = FaceDir[static_cast(moveDir.x)][static_cast(moveDir.y)]; } @@ -675,9 +675,9 @@ int GetItemIdOnSlot(int slot) Size GetItemSizeOnSlot(int slot) { if (slot >= SLOTXY_INV_FIRST && slot <= SLOTXY_INV_LAST) { - int8_t ii = GetItemIdOnSlot(slot); + const int8_t ii = GetItemIdOnSlot(slot); if (ii != 0) { - Item &item = MyPlayer->InvList[ii - 1]; + const Item &item = MyPlayer->InvList[ii - 1]; if (!item.isEmpty()) { return GetInventorySize(item); } @@ -693,9 +693,9 @@ Size GetItemSizeOnSlot(int slot) Size GetItemSizeOnSlot(Point slot) { if (Rectangle { { 0, 0 }, { 10, 10 } }.contains(slot)) { - StashStruct::StashCell ii = Stash.GetItemIdAtPosition(slot); + const StashStruct::StashCell ii = Stash.GetItemIdAtPosition(slot); if (ii != StashStruct::EmptyCell) { - Item &item = Stash.stashList[ii]; + const Item &item = Stash.stashList[ii]; if (!item.isEmpty()) { return GetInventorySize(item); } @@ -743,7 +743,7 @@ void ResetInvCursorPosition() Size itemSize = { 1, 1 }; if (MyPlayer->HoldItem.isEmpty()) { - int8_t itemInvId = GetItemIdOnSlot(Slot); + const int8_t itemInvId = GetItemIdOnSlot(Slot); if (itemInvId != 0) { slot = FindFirstSlotOnItem(itemInvId); itemSize = GetItemSizeOnSlot(Slot); @@ -772,7 +772,7 @@ int FindClosestInventorySlot( int bestSlot = 0; auto checkCandidateSlot = [&](int slot) { - int distance = distanceFunction(mousePos, slot); + const int distance = distanceFunction(mousePos, slot); if (distance < shortestDistance) { shortestDistance = distance; bestSlot = slot; @@ -785,7 +785,7 @@ int FindClosestInventorySlot( } } else { if (heldItem._itype == ItemType::Ring) { - for (int i : { SLOTXY_RING_LEFT, SLOTXY_RING_RIGHT }) { + for (const int i : { SLOTXY_RING_LEFT, SLOTXY_RING_RIGHT }) { checkCandidateSlot(i); } } else if (heldItem.isWeapon()) { @@ -812,8 +812,8 @@ Point FindClosestStashSlot(Point mousePos) int shortestDistance = std::numeric_limits::max(); Point bestSlot = {}; - for (Point point : PointsInRectangle(Rectangle { { 0, 0 }, Size { 10, 10 } })) { - int distance = mousePos.ManhattanDistance(GetStashSlotCoord(point)); + for (const Point point : PointsInRectangle(Rectangle { { 0, 0 }, Size { 10, 10 } })) { + const int distance = mousePos.ManhattanDistance(GetStashSlotCoord(point)); if (distance < shortestDistance) { shortestDistance = distance; bestSlot = point; @@ -825,14 +825,14 @@ Point FindClosestStashSlot(Point mousePos) void LiftInventoryItem() { - int inventorySlot = (Slot >= 0) ? Slot : FindClosestInventorySlot(MousePosition, MyPlayer->HoldItem); + const int inventorySlot = (Slot >= 0) ? Slot : FindClosestInventorySlot(MousePosition, MyPlayer->HoldItem); int jumpSlot = inventorySlot; // If the cursor is over an inventory slot we may need to adjust it due to pasting items of different sizes over each other if (inventorySlot >= SLOTXY_INV_FIRST && inventorySlot <= SLOTXY_INV_LAST) { const Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem); // Find any item occupying a slot that is currently under the cursor - int8_t itemUnderCursor = [](int inventorySlot, Size cursorSizeInCells) { + const int8_t itemUnderCursor = [](int inventorySlot, Size cursorSizeInCells) { if (inventorySlot < SLOTXY_INV_FIRST || inventorySlot > SLOTXY_INV_LAST) return 0; for (int x = 0; x < cursorSizeInCells.width; x++) { @@ -866,25 +866,25 @@ void LiftInventoryItem() void LiftStashItem() { - Point stashSlot = (ActiveStashSlot != InvalidStashPoint) ? ActiveStashSlot : FindClosestStashSlot(MousePosition); + const Point stashSlot = (ActiveStashSlot != InvalidStashPoint) ? ActiveStashSlot : FindClosestStashSlot(MousePosition); Size cursorSizeInCells = MyPlayer->HoldItem.isEmpty() ? Size { 1, 1 } : GetInventorySize(MyPlayer->HoldItem); // Find any item occupying a slot that is currently under the cursor - StashStruct::StashCell itemUnderCursor = [](Point stashSlot, Size cursorSizeInCells) -> StashStruct::StashCell { + const StashStruct::StashCell itemUnderCursor = [](Point stashSlot, Size cursorSizeInCells) -> StashStruct::StashCell { if (stashSlot == InvalidStashPoint) return StashStruct::EmptyCell; - for (Point slotUnderCursor : PointsInRectangle(Rectangle { stashSlot, cursorSizeInCells })) { + for (const Point slotUnderCursor : PointsInRectangle(Rectangle { stashSlot, cursorSizeInCells })) { if (slotUnderCursor.x >= 10 || slotUnderCursor.y >= 10) continue; - StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slotUnderCursor); + const StashStruct::StashCell itemId = Stash.GetItemIdAtPosition(slotUnderCursor); if (itemId != StashStruct::EmptyCell) return itemId; } return StashStruct::EmptyCell; }(stashSlot, cursorSizeInCells); - Point jumpSlot = itemUnderCursor == StashStruct::EmptyCell ? stashSlot : FindFirstStashSlotOnItem(itemUnderCursor); + const Point jumpSlot = itemUnderCursor == StashStruct::EmptyCell ? stashSlot : FindFirstStashSlotOnItem(itemUnderCursor); CheckStashItem(MousePosition); Point mousePos = GetStashSlotCoord(jumpSlot); @@ -951,7 +951,7 @@ void InventoryMove(AxisDirection dir) } else if (Slot == SLOTXY_RING_RIGHT) { Slot = SLOTXY_RING_LEFT; } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_BELT_LAST) { - int8_t itemId = GetItemIdOnSlot(Slot); + const int8_t itemId = GetItemIdOnSlot(Slot); if (itemId != 0) { for (int i = 1; i < INV_ROW_SLOT_SIZE && !IsAnyOf(Slot - i + 1, SLOTXY_INV_ROW1_FIRST, SLOTXY_INV_ROW2_FIRST, SLOTXY_INV_ROW3_FIRST, SLOTXY_INV_ROW4_FIRST, SLOTXY_BELT_FIRST); i++) { if (itemId != GetItemIdOnSlot(Slot - i)) { @@ -985,7 +985,7 @@ void InventoryMove(AxisDirection dir) } else if (Slot == SLOTXY_HEAD) { Slot = SLOTXY_AMULET; } else if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_BELT_LAST) { - int8_t itemId = GetItemIdOnSlot(Slot); + const int8_t itemId = GetItemIdOnSlot(Slot); if (itemId != 0) { for (int i = 1; i < INV_ROW_SLOT_SIZE && !IsAnyOf(Slot + i - 1, SLOTXY_INV_ROW1_LAST, SLOTXY_INV_ROW2_LAST, SLOTXY_INV_ROW3_LAST, SLOTXY_INV_ROW4_LAST, SLOTXY_BELT_LAST); i++) { if (itemId != GetItemIdOnSlot(Slot + i)) { @@ -1034,7 +1034,7 @@ void InventoryMove(AxisDirection dir) } else if (Slot == SLOTXY_HAND_RIGHT) { Slot = SLOTXY_AMULET; } else if (Slot >= SLOTXY_INV_ROW2_FIRST) { - int8_t itemId = GetItemIdOnSlot(Slot); + const int8_t itemId = GetItemIdOnSlot(Slot); if (itemId != 0) { for (int i = 1; i < 5; i++) { if (Slot - i * INV_ROW_SLOT_SIZE < SLOTXY_INV_ROW1_FIRST) { @@ -1090,7 +1090,7 @@ void InventoryMove(AxisDirection dir) } else if (Slot == SLOTXY_HAND_RIGHT) { Slot = SLOTXY_RING_RIGHT; } else if (Slot <= SLOTXY_INV_LAST) { - int8_t itemId = GetItemIdOnSlot(Slot); + const int8_t itemId = GetItemIdOnSlot(Slot); if (itemId != 0) { for (int i = 1; i < 5 && Slot + i * INV_ROW_SLOT_SIZE <= SLOTXY_BELT_LAST; i++) { if (itemId != GetItemIdOnSlot(Slot + i * INV_ROW_SLOT_SIZE)) { @@ -1118,7 +1118,7 @@ void InventoryMove(AxisDirection dir) if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if (!isHoldingItem) { // If we're not holding an item - int8_t itemInvId = GetItemIdOnSlot(Slot); + const int8_t itemInvId = GetItemIdOnSlot(Slot); if (itemInvId != 0) { // but the cursor moved over an item int itemSlot = FindFirstSlotOnItem(itemInvId); @@ -1188,15 +1188,15 @@ void StashMove(AxisDirection dir) if (dir.x == AxisDirectionX_NONE && dir.y == AxisDirectionY_NONE) return; - Item &holdItem = MyPlayer->HoldItem; + const Item &holdItem = MyPlayer->HoldItem; if (Slot < 0 && ActiveStashSlot == InvalidStashPoint) { - int invSlot = FindClosestInventorySlot(MousePosition, holdItem); - Point invSlotCoord = GetSlotCoord(invSlot); - int invDistance = MousePosition.ManhattanDistance(invSlotCoord); + const int invSlot = FindClosestInventorySlot(MousePosition, holdItem); + const Point invSlotCoord = GetSlotCoord(invSlot); + const int invDistance = MousePosition.ManhattanDistance(invSlotCoord); - Point stashSlot = FindClosestStashSlot(MousePosition); - Point stashSlotCoord = GetStashSlotCoord(stashSlot); - int stashDistance = MousePosition.ManhattanDistance(stashSlotCoord); + const Point stashSlot = FindClosestStashSlot(MousePosition); + const Point stashSlotCoord = GetStashSlotCoord(stashSlot); + const int stashDistance = MousePosition.ManhattanDistance(stashSlotCoord); if (invDistance < stashDistance) { BeltReturnsToStash = false; @@ -1212,7 +1212,7 @@ void StashMove(AxisDirection dir) if (dir.y == AxisDirectionY_UP) { // Check if we need to jump from belt to stash if (BeltReturnsToStash && Slot >= SLOTXY_BELT_FIRST && Slot <= SLOTXY_BELT_LAST) { - int beltSlot = Slot - SLOTXY_BELT_FIRST; + const int beltSlot = Slot - SLOTXY_BELT_FIRST; InvalidateInventorySlot(); ActiveStashSlot = { 2 + beltSlot, 10 - itemSize.height }; dir.y = AxisDirectionY_NONE; @@ -1224,7 +1224,7 @@ void StashMove(AxisDirection dir) int firstSlot = Slot; if (Slot >= SLOTXY_INV_FIRST && Slot <= SLOTXY_INV_LAST) { if (MyPlayer->HoldItem.isEmpty()) { - int8_t itemId = GetItemIdOnSlot(Slot); + const int8_t itemId = GetItemIdOnSlot(Slot); if (itemId != 0) { firstSlot = FindFirstSlotOnItem(itemId); } @@ -1234,7 +1234,7 @@ void StashMove(AxisDirection dir) // If we're in the leftmost column (or hovering over an item on the left side of the inventory) or // left side of the body and we're moving left we need to move into the closest stash column if (IsAnyOf(firstSlot, SLOTXY_HEAD, SLOTXY_HAND_LEFT, SLOTXY_RING_LEFT, SLOTXY_AMULET, SLOTXY_CHEST, SLOTXY_INV_ROW1_FIRST, SLOTXY_INV_ROW2_FIRST, SLOTXY_INV_ROW3_FIRST, SLOTXY_INV_ROW4_FIRST)) { - Point slotCoord = GetSlotCoord(Slot); + const Point slotCoord = GetSlotCoord(Slot); InvalidateInventorySlot(); ActiveStashSlot = FindClosestStashSlot(slotCoord) - Displacement { itemSize.width - 1, 0 }; dir.x = AxisDirectionX_NONE; @@ -1260,7 +1260,7 @@ void StashMove(AxisDirection dir) // If we're empty-handed and trying to move right while hovering over an item we may not // have a free stash column to move to. If the item we're hovering over occupies the last // column then we want to jump to the inventory instead of just moving one column over. - Size itemUnderCursorSize = holdItem.isEmpty() ? GetItemSizeOnSlot(ActiveStashSlot) : itemSize; + const Size itemUnderCursorSize = holdItem.isEmpty() ? GetItemSizeOnSlot(ActiveStashSlot) : itemSize; if (ActiveStashSlot.x < 10 - itemUnderCursorSize.width) { const StashStruct::StashCell itemIdAtActiveStashSlot = Stash.GetItemIdAtPosition(ActiveStashSlot); ActiveStashSlot.x++; @@ -1270,10 +1270,10 @@ void StashMove(AxisDirection dir) } } } else { - Point stashSlotCoord = GetStashSlotCoord(ActiveStashSlot); - Point rightPanelCoord = { GetRightPanel().position.x, stashSlotCoord.y }; + const Point stashSlotCoord = GetStashSlotCoord(ActiveStashSlot); + const Point rightPanelCoord = { GetRightPanel().position.x, stashSlotCoord.y }; Slot = FindClosestInventorySlot(rightPanelCoord, holdItem, [](Point mousePos, int slot) { - Point slotPos = GetSlotCoord(slot); + const Point slotPos = GetSlotCoord(slot); // Exaggerate the vertical difference so that moving from the top 6 rows of the // stash is more likely to land on a body slot. The value 3 was found by trial and // error, this allows moving from the top row of the stash to the head while @@ -1306,7 +1306,7 @@ void StashMove(AxisDirection dir) } } } else if ((holdItem.isEmpty() || CanBePlacedOnBelt(*MyPlayer, holdItem)) && ActiveStashSlot.x > 1) { - int beltSlot = ActiveStashSlot.x - 2; + const int beltSlot = ActiveStashSlot.x - 2; Slot = SLOTXY_BELT_FIRST + beltSlot; ActiveStashSlot = InvalidStashPoint; BeltReturnsToStash = true; @@ -1352,8 +1352,8 @@ void HotSpellMove(AxisDirection dir) Point position = MousePosition; int shortestDistance = std::numeric_limits::max(); for (auto &spellListItem : spellListItems) { - Point center = spellListItem.location + Displacement { SPLICONLENGTH / 2, -SPLICONLENGTH / 2 }; - int distance = MousePosition.ManhattanDistance(center); + const Point center = spellListItem.location + Displacement { SPLICONLENGTH / 2, -SPLICONLENGTH / 2 }; + const int distance = MousePosition.ManhattanDistance(center); if (distance < shortestDistance) { position = center; shortestDistance = distance; @@ -1371,7 +1371,7 @@ void HotSpellMove(AxisDirection dir) if (spellListItem.isSelected) continue; - Point center = spellListItem.location + Displacement { SPLICONLENGTH / 2, -SPLICONLENGTH / 2 }; + const Point center = spellListItem.location + Displacement { SPLICONLENGTH / 2, -SPLICONLENGTH / 2 }; if (dir.x == AxisDirectionX_LEFT && center.x >= MousePosition.x) continue; if (dir.x == AxisDirectionX_RIGHT && center.x <= MousePosition.x) @@ -1432,7 +1432,7 @@ bool IsPathBlocked(Point position, Direction dir) if (IsTileNotSolid(leftStep) && IsTileNotSolid(rightStep)) return false; - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; return !PosOkPlayer(myPlayer, leftStep) && !PosOkPlayer(myPlayer, rightStep); } @@ -1724,7 +1724,7 @@ void DetectInputMethod(const SDL_Event &event, const ControllerButtonEvent &game } #endif - ControlTypes newControlDevice = inputType; + const ControlTypes newControlDevice = inputType; ControlTypes newControlMode = inputType; if (ContinueSimulatedMouseEvent(event, gamepadEvent)) { newControlMode = ControlMode; @@ -1956,14 +1956,14 @@ void plrctrls_after_game_logic() void UseBeltItem(BeltItemType type) { for (int i = 0; i < MaxBeltItems; i++) { - Item &item = MyPlayer->SpdList[i]; + const Item &item = MyPlayer->SpdList[i]; if (item.isEmpty()) { continue; } - bool isRejuvenation = IsAnyOf(item._iMiscId, IMISC_REJUV, IMISC_FULLREJUV) || (item._iMiscId == IMISC_ARENAPOT && MyPlayer->isOnArenaLevel()); - bool isHealing = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_HEAL, IMISC_FULLHEAL) || item.isScrollOf(SpellID::Healing); - bool isMana = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_MANA, IMISC_FULLMANA); + const bool isRejuvenation = IsAnyOf(item._iMiscId, IMISC_REJUV, IMISC_FULLREJUV) || (item._iMiscId == IMISC_ARENAPOT && MyPlayer->isOnArenaLevel()); + const bool isHealing = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_HEAL, IMISC_FULLHEAL) || item.isScrollOf(SpellID::Healing); + const bool isMana = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_MANA, IMISC_FULLMANA); if ((type == BeltItemType::Healing && isHealing) || (type == BeltItemType::Mana && isMana)) { UseInvItem(INVITEM_BELT_FIRST + i); @@ -2005,7 +2005,7 @@ void PerformPrimaryAction() bool SpellHasActorTarget() { - SpellID spl = MyPlayer->_pRSpell; + const SpellID spl = MyPlayer->_pRSpell; if (spl == SpellID::TownPortal || spl == SpellID::Teleport) return false; @@ -2024,9 +2024,9 @@ void UpdateSpellTarget(SpellID spell) PlayerUnderCursor = nullptr; pcursmonst = -1; - Player &myPlayer = *MyPlayer; + const Player &myPlayer = *MyPlayer; - int range = spell == SpellID::Teleport ? 4 : 1; + const int range = spell == SpellID::Teleport ? 4 : 1; cursPosition = myPlayer.position.future + Displacement(myPlayer._pdir) * range; } @@ -2100,7 +2100,7 @@ void PerformSpellAction() NewCursor(CURSOR_HAND); const Player &myPlayer = *MyPlayer; - SpellID spl = myPlayer._pRSpell; + const SpellID spl = myPlayer._pRSpell; if ((PlayerUnderCursor == nullptr && (spl == SpellID::Resurrect || spl == SpellID::HealOther)) || (ObjectUnderCursor == nullptr && spl == SpellID::TrapDisarm)) { myPlayer.Say(HeroSpeech::ICantCastThatHere); @@ -2124,7 +2124,7 @@ void CtrlUseInvItem() } Player &myPlayer = *MyPlayer; - Item &item = GetInventoryItem(myPlayer, pcursinvitem); + const Item &item = GetInventoryItem(myPlayer, pcursinvitem); if (item.isScroll()) { if (TargetsMonster(item._iSpell)) { return; @@ -2134,7 +2134,7 @@ void CtrlUseInvItem() } } - int itemId = GetItemIdOnSlot(Slot); + const int itemId = GetItemIdOnSlot(Slot); if (item.isEquipment()) { CheckInvItem(true, false); // auto-equip if it's an equipment } else { diff --git a/Source/hwcursor.hpp b/Source/hwcursor.hpp index bcaad5dcd..2c23b5b59 100644 --- a/Source/hwcursor.hpp +++ b/Source/hwcursor.hpp @@ -77,7 +77,7 @@ public: enabled_ = value; } - [[nodiscard]] bool needsReinitialization() + [[nodiscard]] bool needsReinitialization() const { return needs_reinitialization_; } diff --git a/Source/items.cpp b/Source/items.cpp index 6b3ad048d..0524c6392 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3158,11 +3158,11 @@ Item *SpawnUnique(_unique_items uid, Point position, std::optional level /* if (level) curlv = *level; const ItemData &uniqueItemData = AllItemsList[idx]; - _item_indexes idx = GetItemIndexForDroppableItem(false, [&uniqueItemData](const ItemData &item) { + _item_indexes dropIdx = GetItemIndexForDroppableItem(false, [&uniqueItemData](const ItemData &item) { return item.itype == uniqueItemData.itype; }); - SetupAllItems(*MyPlayer, item, idx, AdvanceRndSeed(), curlv * 2, 15, true, false); - TryRandomUniqueItem(item, idx, curlv * 2, 15, true, false); + SetupAllItems(*MyPlayer, item, dropIdx, AdvanceRndSeed(), curlv * 2, 15, true, false); + TryRandomUniqueItem(item, dropIdx, curlv * 2, 15, true, false); SetupItem(item); } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index ca2654315..598a305a3 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -130,7 +130,7 @@ public: && m_size_ >= (m_cur_ + size); } - size_t Size() + size_t Size() const { return m_size_; } diff --git a/Source/monster.cpp b/Source/monster.cpp index a0e24e3f9..474e9aeda 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3428,9 +3428,9 @@ tl::expected InitMonsterGFX(CMonster &monsterType, MonsterSpr } const uint32_t begin = spritesData.offsets[j]; const uint32_t end = spritesData.offsets[j + 1]; - auto spritesData = reinterpret_cast(&monsterType.animData[begin]); - const uint16_t numLists = GetNumListsFromClxListOrSheetBuffer(spritesData, end - begin); - monsterType.anims[i].sprites = ClxSpriteListOrSheet { spritesData, numLists }; + auto animSpritesData = reinterpret_cast(&monsterType.animData[begin]); + const uint16_t numLists = GetNumListsFromClxListOrSheetBuffer(animSpritesData, end - begin); + monsterType.anims[i].sprites = ClxSpriteListOrSheet { animSpritesData, numLists }; ++j; } @@ -4786,9 +4786,9 @@ Monster *Monster::getLeader() const return &Monsters[leader]; } -void Monster::setLeader(const Monster *leader) +void Monster::setLeader(const Monster *newLeader) { - if (leader == nullptr) { + if (newLeader == nullptr) { // really we should update this->leader to NoLeader to avoid leaving a dangling reference to a dead monster // when passed nullptr. So that buffed minions are drawn with a distinct colour in monhealthbar we leave the // reference and hope that no code tries to modify the leader through this instance later. @@ -4796,9 +4796,9 @@ void Monster::setLeader(const Monster *leader) return; } - this->leader = static_cast(leader->getId()); + this->leader = static_cast(newLeader->getId()); leaderRelation = LeaderRelation::Leashed; - ai = leader->ai; + ai = newLeader->ai; } [[nodiscard]] unsigned Monster::distanceToEnemy() const @@ -4935,10 +4935,10 @@ unsigned int Monster::toHitSpecial(_difficulty difficulty) const return baseToHitSpecial; } -void Monster::occupyTile(Point position, bool isMoving) const +void Monster::occupyTile(Point tile, bool isMoving) const { int16_t id = static_cast(this->getId() + 1); - dMonster[position.x][position.y] = isMoving ? -id : id; + dMonster[tile.x][tile.y] = isMoving ? -id : id; } } // namespace devilution diff --git a/Source/objdat.cpp b/Source/objdat.cpp index 687d0c346..9b54109b5 100644 --- a/Source/objdat.cpp +++ b/Source/objdat.cpp @@ -271,14 +271,14 @@ void LoadObjectData() reader.advance(); // skip id - std::string filename; - reader.readString("file", filename); - if (const auto it = filenameToId.find(filename); it != filenameToId.end()) { + std::string objFilename; + reader.readString("file", objFilename); + if (const auto it = filenameToId.find(objFilename); it != filenameToId.end()) { item.ofindex = it->second; } else { const auto id = static_cast(ObjMasterLoadList.size()); - ObjMasterLoadList.push_back(filename); - filenameToId.emplace(std::move(filename), id); + ObjMasterLoadList.push_back(objFilename); + filenameToId.emplace(std::move(objFilename), id); item.ofindex = id; } diff --git a/Source/options.cpp b/Source/options.cpp index bf7af99d4..2a09517cf 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -294,9 +294,9 @@ void OptionEntryBoolean::SaveToIni(std::string_view category) const { ini->set(category, key, value); } -void OptionEntryBoolean::SetValue(bool value) +void OptionEntryBoolean::SetValue(bool newValue) { - this->value = value; + this->value = newValue; this->NotifyValueChanged(); } OptionEntryType OptionEntryBoolean::GetType() const @@ -325,14 +325,14 @@ void OptionEntryEnumBase::SaveToIni(std::string_view category) const { ini->set(category, key, value); } -void OptionEntryEnumBase::SetValueInternal(int value) +void OptionEntryEnumBase::SetValueInternal(int newValue) { - this->value = value; + this->value = newValue; this->NotifyValueChanged(); } -void OptionEntryEnumBase::AddEntry(int value, std::string_view name) +void OptionEntryEnumBase::AddEntry(int entryValue, std::string_view name) { - entryValues.push_back(value); + entryValues.push_back(entryValue); entryNames.push_back(name); } size_t OptionEntryEnumBase::GetListSize() const @@ -368,14 +368,14 @@ void OptionEntryIntBase::SaveToIni(std::string_view category) const { ini->set(category, key, value); } -void OptionEntryIntBase::SetValueInternal(int value) +void OptionEntryIntBase::SetValueInternal(int newValue) { - this->value = value; + this->value = newValue; this->NotifyValueChanged(); } -void OptionEntryIntBase::AddEntry(int value) +void OptionEntryIntBase::AddEntry(int entryValue) { - entryValues.push_back(value); + entryValues.push_back(entryValue); } size_t OptionEntryIntBase::GetListSize() const { @@ -384,8 +384,8 @@ size_t OptionEntryIntBase::GetListSize() const std::string_view OptionEntryIntBase::GetListDescription(size_t index) const { if (entryNames.empty()) { - for (auto value : entryValues) { - entryNames.push_back(StrCat(value)); + for (auto entryValue : entryValues) { + entryNames.push_back(StrCat(entryValue)); } } return entryNames[index].data(); diff --git a/Source/options.h b/Source/options.h index c2a86f1fb..b18ed5c9d 100644 --- a/Source/options.h +++ b/Source/options.h @@ -233,8 +233,8 @@ public: OptionEntryEnum(std::string_view key, OptionEntryFlags flags, const char *name, const char *description, T defaultValue, std::initializer_list> entries) : OptionEntryEnumBase(key, flags, name, description, static_cast(defaultValue)) { - for (auto &&[key, value] : entries) { - AddEntry(static_cast(key), value); + for (auto &&[entryValue, entryName] : entries) { + AddEntry(static_cast(entryValue), entryName); } } [[nodiscard]] T operator*() const diff --git a/Source/pfile.cpp b/Source/pfile.cpp index 4f98a2af7..dfc7cc921 100644 --- a/Source/pfile.cpp +++ b/Source/pfile.cpp @@ -254,11 +254,11 @@ struct CompareInfo { struct CompareCounter { int reference; int actual; - int max() + int max() const { return std::max(reference, actual); } - void checkIfDataExists(int count, CompareInfo &compareInfoReference, CompareInfo &compareInfoActual) + void checkIfDataExists(int count, CompareInfo &compareInfoReference, CompareInfo &compareInfoActual) const { if (reference == count) compareInfoReference.dataExists = false; diff --git a/Source/player.cpp b/Source/player.cpp index 9411f8c57..2c04ea456 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -1925,7 +1925,7 @@ void Player::UpdatePreviewCelSprite(_cmd_id cmdId, Point point, uint16_t wParam1 if (minimalWalkDistance >= 0 && position.future != point) { int8_t testWalkPath[MaxPathLengthPlayer]; - int steps = FindPath(CanStep, [this](Point position) { return PosOkPlayer(*this, position); }, position.future, point, testWalkPath, MaxPathLengthPlayer); + int steps = FindPath(CanStep, [this](Point tile) { return PosOkPlayer(*this, tile); }, position.future, point, testWalkPath, MaxPathLengthPlayer); if (steps == 0) { // Can't walk to desired location => stand still return; @@ -2001,11 +2001,11 @@ int32_t Player::calculateBaseMana() const return attr.adjMana + (attr.lvlMana * getCharacterLevel()) + (attr.chrMana * _pBaseMag); } -void Player::occupyTile(Point position, bool isMoving) const +void Player::occupyTile(Point tilePosition, bool isMoving) const { int16_t id = this->getId(); id += 1; - dPlayer[position.x][position.y] = isMoving ? -id : id; + dPlayer[tilePosition.x][tilePosition.y] = isMoving ? -id : id; } bool Player::isLevelOwnedByLocalClient() const diff --git a/Source/quests.cpp b/Source/quests.cpp index 4939ee42c..eddeff21a 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -349,16 +349,16 @@ void CheckQuests() StartPWaterPurify(); } } else if (MyPlayer->_pmode == PM_STAND) { - for (auto &quest : Quests) { - if (currlevel == quest._qlevel - && quest._qslvl != 0 - && quest._qactive != QUEST_NOTAVAIL - && MyPlayer->position.tile == quest.position - && (quest._qidx != Q_BETRAYER || quest._qvar1 >= 3)) { - if (quest._qlvltype != DTYPE_NONE) { - setlvltype = quest._qlvltype; + for (auto ¤tQuest : Quests) { + if (currlevel == currentQuest._qlevel + && currentQuest._qslvl != 0 + && currentQuest._qactive != QUEST_NOTAVAIL + && MyPlayer->position.tile == currentQuest.position + && (currentQuest._qidx != Q_BETRAYER || currentQuest._qvar1 >= 3)) { + if (currentQuest._qlvltype != DTYPE_NONE) { + setlvltype = currentQuest._qlvltype; } - StartNewLvl(*MyPlayer, WM_DIABSETLVL, quest._qslvl); + StartNewLvl(*MyPlayer, WM_DIABSETLVL, currentQuest._qslvl); } } } @@ -934,7 +934,7 @@ bool UseMultiplayerQuests() return sgGameInitInfo.fullQuests == 0; } -bool Quest::IsAvailable() +bool Quest::IsAvailable() const { if (setlevel) return false; diff --git a/Source/quests.h b/Source/quests.h index da39f4217..a0d2f935e 100644 --- a/Source/quests.h +++ b/Source/quests.h @@ -91,7 +91,7 @@ struct Quest { uint8_t _qvar1; uint8_t _qvar2; - bool IsAvailable(); + bool IsAvailable() const; }; struct QuestData {