diff --git a/Source/control.cpp b/Source/control.cpp index 97390c73153..d5c8edae227 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1213,7 +1213,7 @@ void DrawInfoBox(const Surface &out) GetObjectStr(*ObjectUnderCursor); if (pcursmonst != -1) { if (leveltype != DTYPE_TOWN) { - const auto &monster = Monsters[pcursmonst]; + const Monster &monster = Monsters[pcursmonst]; InfoColor = UiFlags::ColorWhite; InfoString = monster.name(); if (monster.isUnique()) { diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index aba2e782e43..335f8c3bdee 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -165,7 +165,7 @@ void FindItemOrObject() continue; } - auto &item = Items[itemId]; + Item &item = Items[itemId]; if (item.isEmpty() || item._iSelFlag == 0) { continue; } @@ -266,7 +266,7 @@ void FindRangedTarget() for (size_t i = 0; i < ActiveMonsterCount; i++) { int mi = ActiveMonsters[i]; - const auto &monster = Monsters[mi]; + const Monster &monster = Monsters[mi]; if (!CanTargetMonster(monster)) continue; @@ -332,7 +332,7 @@ void FindMeleeTarget() if (dMonster[dx][dy] != 0) { const int mi = std::abs(dMonster[dx][dy]) - 1; - const auto &monster = Monsters[mi]; + const Monster &monster = Monsters[mi]; if (CanTargetMonster(monster)) { const bool newCanTalk = CanTalkToMonst(monster); if (pcursmonst != -1 && !canTalk && newCanTalk) diff --git a/Source/controls/touch/renderers.cpp b/Source/controls/touch/renderers.cpp index 5a610f9996b..a10f7b564d7 100644 --- a/Source/controls/touch/renderers.cpp +++ b/Source/controls/touch/renderers.cpp @@ -438,7 +438,7 @@ VirtualGamepadButtonType PrimaryActionButtonRenderer::GetTownButtonType() VirtualGamepadButtonType PrimaryActionButtonRenderer::GetDungeonButtonType() { if (pcursmonst != -1) { - const auto &monster = Monsters[pcursmonst]; + const Monster &monster = Monsters[pcursmonst]; if (M_Talker(monster) || monster.talkMsg != TEXT_NONE) return GetTalkButtonType(virtualPadButton->isHeld); } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 1130a5fc215..eebe60ba1ba 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1391,7 +1391,7 @@ void UnstuckChargers() } } for (size_t i = 0; i < ActiveMonsterCount; i++) { - auto &monster = Monsters[ActiveMonsters[i]]; + Monster &monster = Monsters[ActiveMonsters[i]]; if (monster.mode == MonsterMode::Charge) monster.mode = MonsterMode::Stand; } @@ -1400,7 +1400,7 @@ void UnstuckChargers() void UpdateMonsterLights() { for (size_t i = 0; i < ActiveMonsterCount; i++) { - auto &monster = Monsters[ActiveMonsters[i]]; + Monster &monster = Monsters[ActiveMonsters[i]]; if ((monster.flags & MFLAG_BERSERK) != 0) { int lightRadius = leveltype == DTYPE_NEST ? 9 : 3; diff --git a/Source/inv.cpp b/Source/inv.cpp index f10da757402..19c9ca78516 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -325,237 +325,278 @@ int FindTargetSlotUnderItemCursor(Point cursorPosition, Size itemSize) return NUM_XY_SLOTS; } -void CheckInvPaste(Player &player, Point cursorPosition) +void ChangeBodyEquipment(Player &player, int slot, item_equip_type location) { - Size itemSize = GetInventorySize(player.HoldItem); - - int slot = FindTargetSlotUnderItemCursor(cursorPosition, itemSize); - if (slot == NUM_XY_SLOTS) - return; - - item_equip_type il = ILOC_UNEQUIPABLE; - if (slot == SLOTXY_HEAD) - il = ILOC_HELM; - if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_RING_RIGHT) - il = ILOC_RING; - if (slot == SLOTXY_AMULET) - il = ILOC_AMULET; - if (slot == SLOTXY_HAND_LEFT || slot == SLOTXY_HAND_RIGHT) - il = ILOC_ONEHAND; - if (slot == SLOTXY_CHEST) - il = ILOC_ARMOR; - if (slot >= SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) - il = ILOC_BELT; - - item_equip_type desiredIl = player.GetItemLocation(player.HoldItem); - if (il == ILOC_ONEHAND && desiredIl == ILOC_TWOHAND) - il = ILOC_TWOHAND; - - int8_t it = 0; - if (il == ILOC_UNEQUIPABLE) { - int ii = slot - SLOTXY_INV_FIRST; - if (player.HoldItem._itype == ItemType::Gold) { - if (player.InvGrid[ii] != 0) { - int8_t iv = player.InvGrid[ii]; - if (iv > 0) { - if (player.InvList[iv - 1]._itype != ItemType::Gold) { - it = iv; - } - } else { - it = -iv; - } - } - } else { - // check that the item we're pasting only overlaps one other item (or is going into empty space) - unsigned originCell = static_cast(slot - SLOTXY_INV_FIRST); - for (unsigned rowOffset = 0; rowOffset < static_cast(itemSize.height * InventorySizeInSlots.width); rowOffset += InventorySizeInSlots.width) { - for (unsigned columnOffset = 0; columnOffset < static_cast(itemSize.width); columnOffset++) { - unsigned testCell = originCell + rowOffset + columnOffset; - // FindTargetSlotUnderItemCursor returns the top left slot of the inventory region that fits the item, we can be confident this calculation is not going to read out of range. - assert(testCell < sizeof(player.InvGrid)); - if (player.InvGrid[testCell] != 0) { - int8_t iv = std::abs(player.InvGrid[testCell]); - if (it != 0) { - if (it != iv) { - // Found two different items that would be displaced by the held item, can't paste the item here. - return; - } - } else { - it = iv; - } - } - } - } - } - } else if (il == ILOC_BELT) { - if (!CanBePlacedOnBelt(player, player.HoldItem)) - return; - } else if (desiredIl != il) { - return; + const inv_body_loc bodyLocation = [&slot](item_equip_type location) { + switch (location) { + case ILOC_HELM: + return INVLOC_HEAD; + case ILOC_RING: + return (slot == SLOTXY_RING_LEFT ? INVLOC_RING_LEFT : INVLOC_RING_RIGHT); + case ILOC_AMULET: + return INVLOC_AMULET; + case ILOC_ARMOR: + return INVLOC_CHEST; + default: + app_fatal("Unexpected equipment type"); + } + }(location); + const Item previouslyEquippedItem = player.InvBody[slot]; + ChangeEquipment(player, bodyLocation, player.HoldItem.pop(), &player == MyPlayer); + if (!previouslyEquippedItem.isEmpty()) { + player.HoldItem = previouslyEquippedItem; } +} - if (IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT) && !player.CanUseItem(player.HoldItem)) { - player.Say(HeroSpeech::ICantUseThisYet); - return; - } +void ChangeEquippedItem(Player &player, uint8_t slot) +{ + const inv_body_loc selectedHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_LEFT : INVLOC_HAND_RIGHT; + const inv_body_loc otherHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_RIGHT : INVLOC_HAND_LEFT; - if (player._pmode > PM_WALK_SIDEWAYS && IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT)) - return; + const bool pasteIntoSelectedHand = (player.InvBody[otherHand].isEmpty() || player.InvBody[otherHand]._iClass != player.HoldItem._iClass) + || (player._pClass == HeroClass::Bard && player.InvBody[otherHand]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON); - if (&player == MyPlayer) - PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]); + const bool dequipTwoHandedWeapon = (!player.InvBody[otherHand].isEmpty() && player.GetItemLocation(player.InvBody[otherHand]) == ILOC_TWOHAND); - switch (il) { - case ILOC_HELM: - case ILOC_RING: - case ILOC_AMULET: - case ILOC_ARMOR: { - auto iLocToInvLoc = [&slot](item_equip_type loc) { - switch (loc) { - case ILOC_HELM: - return INVLOC_HEAD; - case ILOC_RING: - return (slot == SLOTXY_RING_LEFT ? INVLOC_RING_LEFT : INVLOC_RING_RIGHT); - case ILOC_AMULET: - return INVLOC_AMULET; - case ILOC_ARMOR: - return INVLOC_CHEST; - default: - app_fatal("Unexpected equipment type"); - } - }; - inv_body_loc slot = iLocToInvLoc(il); - Item previouslyEquippedItem = player.InvBody[slot]; - ChangeEquipment(player, slot, player.HoldItem.pop(), &player == MyPlayer); - if (!previouslyEquippedItem.isEmpty()) { - player.HoldItem = previouslyEquippedItem; - } - break; + const inv_body_loc pasteHand = pasteIntoSelectedHand ? selectedHand : otherHand; + const Item previouslyEquippedItem = dequipTwoHandedWeapon ? player.InvBody[otherHand] : player.InvBody[pasteHand]; + if (dequipTwoHandedWeapon) { + RemoveEquipment(player, otherHand, false); } - case ILOC_ONEHAND: { - inv_body_loc selectedHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_LEFT : INVLOC_HAND_RIGHT; - inv_body_loc otherHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_RIGHT : INVLOC_HAND_LEFT; - - bool pasteIntoSelectedHand = (player.InvBody[otherHand].isEmpty() || player.InvBody[otherHand]._iClass != player.HoldItem._iClass) - || (player._pClass == HeroClass::Bard && player.InvBody[otherHand]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON); + ChangeEquipment(player, pasteHand, player.HoldItem.pop(), &player == MyPlayer); + if (!previouslyEquippedItem.isEmpty()) { + player.HoldItem = previouslyEquippedItem; + } +} - bool dequipTwoHandedWeapon = (!player.InvBody[otherHand].isEmpty() && player.GetItemLocation(player.InvBody[otherHand]) == ILOC_TWOHAND); +void ChangeTwoHandItem(Player &player) +{ + if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && !player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { + inv_body_loc locationToUnequip = INVLOC_HAND_LEFT; + if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Shield) { + locationToUnequip = INVLOC_HAND_RIGHT; + } + if (!AutoPlaceItemInInventory(player, player.InvBody[locationToUnequip], true)) { + return; + } - inv_body_loc pasteHand = pasteIntoSelectedHand ? selectedHand : otherHand; - Item previouslyEquippedItem = dequipTwoHandedWeapon ? player.InvBody[otherHand] : player.InvBody[pasteHand]; - if (dequipTwoHandedWeapon) { - RemoveEquipment(player, otherHand, false); + if (locationToUnequip == INVLOC_HAND_RIGHT) { + RemoveEquipment(player, INVLOC_HAND_RIGHT, false); + } else { + player.InvBody[INVLOC_HAND_LEFT].clear(); } - ChangeEquipment(player, pasteHand, player.HoldItem.pop(), &player == MyPlayer); + } + + if (player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { + Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_LEFT]; + ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem.pop(), &player == MyPlayer); if (!previouslyEquippedItem.isEmpty()) { player.HoldItem = previouslyEquippedItem; } - break; + } else { + Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_RIGHT]; + RemoveEquipment(player, INVLOC_HAND_RIGHT, false); + ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem, &player == MyPlayer); + player.HoldItem = previouslyEquippedItem; } - case ILOC_TWOHAND: - if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && !player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { - inv_body_loc locationToUnequip = INVLOC_HAND_LEFT; - if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ItemType::Shield) { - locationToUnequip = INVLOC_HAND_RIGHT; - } - bool done2h = AutoPlaceItemInInventory(player, player.InvBody[locationToUnequip], true); - if (!done2h) - return; +} - if (locationToUnequip == INVLOC_HAND_RIGHT) { - RemoveEquipment(player, INVLOC_HAND_RIGHT, false); - } else { - // CMD_CHANGEPLRITEMS will eventually be sent for the left hand - player.InvBody[INVLOC_HAND_LEFT].clear(); +int8_t CheckOverlappingItems(int slot, const Player &player, Size itemSize) +{ + // check that the item we're pasting only overlaps one other item (or is going into empty space) + const unsigned originCell = static_cast(slot - SLOTXY_INV_FIRST); + + int8_t overlappingId = 0; + for (unsigned rowOffset = 0; rowOffset < static_cast(itemSize.height * InventorySizeInSlots.width); rowOffset += InventorySizeInSlots.width) { + + for (unsigned columnOffset = 0; columnOffset < static_cast(itemSize.width); columnOffset++) { + unsigned testCell = originCell + rowOffset + columnOffset; + // FindTargetSlotUnderItemCursor returns the top left slot of the inventory region that fits the item, we can be confident this calculation is not going to read out of range. + assert(testCell < sizeof(player.InvGrid)); + if (player.InvGrid[testCell] != 0) { + int8_t iv = std::abs(player.InvGrid[testCell]); + if (overlappingId != 0) { + if (overlappingId != iv) { + // Found two different items that would be displaced by the held item, can't paste the item here. + return -1; + } + } else { + overlappingId = iv; + } } } + } - if (player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) { - Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_LEFT]; - ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem.pop(), &player == MyPlayer); - if (!previouslyEquippedItem.isEmpty()) { - player.HoldItem = previouslyEquippedItem; - } - } else { - Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_RIGHT]; - RemoveEquipment(player, INVLOC_HAND_RIGHT, false); - ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem, &player == MyPlayer); - player.HoldItem = previouslyEquippedItem; - } - break; - case ILOC_UNEQUIPABLE: - if (player.HoldItem._itype == ItemType::Gold && it == 0) { - int ii = slot - SLOTXY_INV_FIRST; - if (player.InvGrid[ii] > 0) { - int invIndex = player.InvGrid[ii] - 1; - int gt = player.InvList[invIndex]._ivalue; - int ig = player.HoldItem._ivalue + gt; - if (ig <= MaxGold) { - player.InvList[invIndex]._ivalue = ig; - SetPlrHandGoldCurs(player.InvList[invIndex]); - player._pGold += player.HoldItem._ivalue; - player.HoldItem.clear(); - } else { - ig = MaxGold - gt; - player._pGold += ig; - player.HoldItem._ivalue -= ig; - SetPlrHandGoldCurs(player.HoldItem); - player.InvList[invIndex]._ivalue = MaxGold; - player.InvList[invIndex]._iCurs = ICURS_GOLD_LARGE; - } - } else { - int invIndex = player._pNumInv; + return overlappingId; +} + +int8_t GetPrevItemId(int slot, const Player &player, const Size &itemSize) +{ + if (player.HoldItem._itype != ItemType::Gold) + return CheckOverlappingItems(slot, player, itemSize); + int8_t item_cell_begin = player.InvGrid[slot - SLOTXY_INV_FIRST]; + if (item_cell_begin == 0) + return 0; + if (item_cell_begin <= 0) + return -item_cell_begin; + if (player.InvList[item_cell_begin - 1]._itype != ItemType::Gold) + return item_cell_begin; + return 0; +} + +bool ChangeInvItem(Player &player, int slot, Size itemSize) +{ + int8_t prevItemId = GetPrevItemId(slot, player, itemSize); + if (prevItemId < 0) return false; + + if (player.HoldItem._itype == ItemType::Gold && prevItemId == 0) { + const int ii = slot - SLOTXY_INV_FIRST; + if (player.InvGrid[ii] > 0) { + const int invIndex = player.InvGrid[ii] - 1; + const int gt = player.InvList[invIndex]._ivalue; + int ig = player.HoldItem._ivalue + gt; + if (ig <= MaxGold) { + player.InvList[invIndex]._ivalue = ig; + SetPlrHandGoldCurs(player.InvList[invIndex]); player._pGold += player.HoldItem._ivalue; - player.InvList[invIndex] = player.HoldItem.pop(); - player._pNumInv++; - player.InvGrid[ii] = player._pNumInv; - } - if (&player == MyPlayer) { - NetSendCmdChInvItem(false, ii); - } - } else { - if (it == 0) { - player.InvList[player._pNumInv] = player.HoldItem.pop(); - player._pNumInv++; - it = player._pNumInv; + player.HoldItem.clear(); } else { - int invIndex = it - 1; - if (player.HoldItem._itype == ItemType::Gold) - player._pGold += player.HoldItem._ivalue; - std::swap(player.InvList[invIndex], player.HoldItem); - if (player.HoldItem._itype == ItemType::Gold) - player._pGold = CalculateGold(player); - for (auto &itemIndex : player.InvGrid) { - if (itemIndex == it) - itemIndex = 0; - if (itemIndex == -it) - itemIndex = 0; - } + ig = MaxGold - gt; + player._pGold += ig; + player.HoldItem._ivalue -= ig; + SetPlrHandGoldCurs(player.HoldItem); + player.InvList[invIndex]._ivalue = MaxGold; + player.InvList[invIndex]._iCurs = ICURS_GOLD_LARGE; } - - AddItemToInvGrid(player, slot - SLOTXY_INV_FIRST, it, itemSize, &player == MyPlayer); + } else { + const int invIndex = player._pNumInv; + player._pGold += player.HoldItem._ivalue; + player.InvList[invIndex] = player.HoldItem.pop(); + player._pNumInv++; + player.InvGrid[ii] = player._pNumInv; } - break; - case ILOC_BELT: { - int ii = slot - SLOTXY_BELT_FIRST; - if (player.SpdList[ii].isEmpty()) { - player.SpdList[ii] = player.HoldItem.pop(); + if (&player == MyPlayer) { + NetSendCmdChInvItem(false, ii); + } + } else { + if (prevItemId == 0) { + player.InvList[player._pNumInv] = player.HoldItem.pop(); + player._pNumInv++; + prevItemId = player._pNumInv; } else { - std::swap(player.SpdList[ii], player.HoldItem); + const int invIndex = prevItemId - 1; + if (player.HoldItem._itype == ItemType::Gold) + player._pGold += player.HoldItem._ivalue; + std::swap(player.InvList[invIndex], player.HoldItem); if (player.HoldItem._itype == ItemType::Gold) player._pGold = CalculateGold(player); + for (int8_t &itemIndex : player.InvGrid) { + if (itemIndex == prevItemId) + itemIndex = 0; + if (itemIndex == -prevItemId) + itemIndex = 0; + } } - if (&player == MyPlayer) { - NetSendCmdChBeltItem(false, ii); + + AddItemToInvGrid(player, slot - SLOTXY_INV_FIRST, prevItemId, itemSize, &player == MyPlayer); + } + + return true; +} + +void ChangeBeltItem(Player &player, int slot) +{ + const int ii = slot - SLOTXY_BELT_FIRST; + if (player.SpdList[ii].isEmpty()) { + player.SpdList[ii] = player.HoldItem.pop(); + } else { + std::swap(player.SpdList[ii], player.HoldItem); + + if (player.HoldItem._itype == ItemType::Gold) + player._pGold = CalculateGold(player); + } + if (&player == MyPlayer) { + NetSendCmdChBeltItem(false, ii); + } + RedrawComponent(PanelDrawComponent::Belt); +} + +item_equip_type GetItemEquipType(const Player &player, int slot, item_equip_type desiredLocation) +{ + if (slot == SLOTXY_HEAD) + return ILOC_HELM; + if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_RING_RIGHT) + return ILOC_RING; + if (slot == SLOTXY_AMULET) + return ILOC_AMULET; + if (slot == SLOTXY_HAND_LEFT || slot == SLOTXY_HAND_RIGHT) { + if (desiredLocation == ILOC_TWOHAND) + return ILOC_TWOHAND; + return ILOC_ONEHAND; + } + if (slot == SLOTXY_CHEST) + return ILOC_ARMOR; + if (slot >= SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) + return ILOC_BELT; + + return ILOC_UNEQUIPABLE; +} + +void CheckInvPaste(Player &player, Point cursorPosition) +{ + const Size itemSize = GetInventorySize(player.HoldItem); + + const int slot = FindTargetSlotUnderItemCursor(cursorPosition, itemSize); + if (slot == NUM_XY_SLOTS) + return; + + const item_equip_type desiredLocation = player.GetItemLocation(player.HoldItem); + const item_equip_type location = GetItemEquipType(player, slot, desiredLocation); + + if (location == ILOC_BELT) { + if (!CanBePlacedOnBelt(player, player.HoldItem)) return; + } else if (location != ILOC_UNEQUIPABLE) { + if (desiredLocation != location) return; + } + + if (IsNoneOf(location, ILOC_UNEQUIPABLE, ILOC_BELT)) { + if (!player.CanUseItem(player.HoldItem)) { + player.Say(HeroSpeech::ICantUseThisYet); + return; } - RedrawComponent(PanelDrawComponent::Belt); - } break; + if (player._pmode > PM_WALK_SIDEWAYS) + return; + } + + // Select the parameters that go into + // ChangeEquipment and add it to post switch + switch (location) { + case ILOC_HELM: + case ILOC_RING: + case ILOC_AMULET: + case ILOC_ARMOR: + ChangeBodyEquipment(player, slot, location); + break; + case ILOC_ONEHAND: + ChangeEquippedItem(player, slot); + break; + case ILOC_TWOHAND: + ChangeTwoHandItem(player); + break; + case ILOC_UNEQUIPABLE: + if (!ChangeInvItem(player, slot, itemSize)) return; + break; + case ILOC_BELT: + ChangeBeltItem(player, slot); + break; case ILOC_NONE: case ILOC_INVALID: break; } + CalcPlrInv(player, true); if (&player == MyPlayer) { + PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]); NewCursor(player.HoldItem); } } @@ -917,7 +958,7 @@ void CheckQuestItem(Player &player, Item &questItem) void CleanupItems(int ii) { - auto &item = Items[ii]; + Item &item = Items[ii]; dItem[item.position.x][item.position.y] = 0; if (CornerStone.isAvailable() && item.position == CornerStone.position) { @@ -1090,7 +1131,7 @@ void DrawInv(const Surface &out) const int cursId = myPlayer.InvBody[slot]._iCurs + CURSOR_FIRSTITEM; - auto frameSize = GetInvItemSize(cursId); + Size frameSize = GetInvItemSize(cursId); // calc item offsets for weapons/armor smaller than 2x3 slots if (IsAnyOf(slot, INVLOC_HAND_LEFT, INVLOC_HAND_RIGHT, INVLOC_CHEST)) { @@ -1200,7 +1241,7 @@ bool AutoPlaceItemInBelt(Player &player, const Item &item, bool persistItem, boo return false; } - for (auto &beltItem : player.SpdList) { + for (Item &beltItem : player.SpdList) { if (beltItem.isEmpty()) { if (persistItem) { beltItem = item; @@ -1519,7 +1560,7 @@ void inv_update_rem_item(Player &player, inv_body_loc iv) void CheckInvSwap(Player &player, const Item &item, int invGridIndex) { - auto itemSize = GetInventorySize(item); + Size itemSize = GetInventorySize(item); const int pitch = 10; int invListIndex = [&]() -> int { @@ -1536,7 +1577,7 @@ void CheckInvSwap(Player &player, const Item &item, int invGridIndex) }(); if (invListIndex < player._pNumInv) { - for (auto &itemIndex : player.InvGrid) { + for (int8_t &itemIndex : player.InvGrid) { if (itemIndex == invListIndex) itemIndex = 0; if (itemIndex == -invListIndex) @@ -1615,7 +1656,7 @@ void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld) void InvGetItem(Player &player, int ii) { - auto &item = Items[ii]; + Item &item = Items[ii]; CloseGoldDrop(); if (dItem[item.position.x][item.position.y] == 0) @@ -1737,7 +1778,7 @@ void AutoGetItem(Player &player, Item *itemPointer, int ii) int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t createInfo) { for (uint8_t i = 0; i < ActiveItemCount; i++) { - auto &item = Items[ActiveItems[i]]; + Item &item = Items[ActiveItems[i]]; if (item.keyAttributesMatch(iseed, idx, createInfo)) { return i; } @@ -1954,7 +1995,7 @@ void ConsumeScroll(Player &player) { const SpellID spellId = player.executedSpell.spellId; - const auto isCurrentSpell = [spellId](const Item &item) { + const auto isCurrentSpell = [spellId](const Item &item) -> bool { return item.isScrollOf(spellId) || item.isRuneOf(spellId); }; @@ -1995,7 +2036,7 @@ bool CanUseScroll(Player &player, SpellID spell) void ConsumeStaffCharge(Player &player) { - auto &staff = player.InvBody[INVLOC_HAND_LEFT]; + Item &staff = player.InvBody[INVLOC_HAND_LEFT]; if (!CanUseStaff(staff, player.executedSpell.spellId)) return; @@ -2201,7 +2242,7 @@ void DoTelekinesis() if (pcursitem != -1) NetSendCmdGItem(true, CMD_REQUESTAGITEM, *MyPlayer, pcursitem); if (pcursmonst != -1) { - auto &monter = Monsters[pcursmonst]; + Monster &monter = Monsters[pcursmonst]; if (!M_Talker(monter) && monter.talkMsg == TEXT_NONE) NetSendCmdParam1(true, CMD_KNOCKBACK, pcursmonst); } @@ -2222,7 +2263,7 @@ int CalculateGold(Player &player) Size GetInventorySize(const Item &item) { - auto size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM); + Size size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM); return { size.width / InventorySlotSizeInPixels.width, size.height / InventorySlotSizeInPixels.height }; } diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 55001c5786a..82339697c04 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -688,7 +688,7 @@ void SyncPackSize(Monster &leader) leader.packSize = 0; for (size_t i = 0; i < ActiveMonsterCount; i++) { - auto &minion = Monsters[ActiveMonsters[i]]; + Monster &minion = Monsters[ActiveMonsters[i]]; if (minion.leaderRelation == LeaderRelation::Leashed && minion.getLeader() == &leader) leader.packSize++; } diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 4446d550855..f9acd02f6b3 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -204,7 +204,7 @@ int ProjectileTrapDamage() bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, int dist, MissileID t, DamageType damageType, bool shift) { - auto &monster = Monsters[monsterId]; + Monster &monster = Monsters[monsterId]; if (!monster.isPossibleToHit() || monster.isImmune(t, damageType)) return false; @@ -936,7 +936,7 @@ Direction16 GetDirection16(Point p1, Point p2) bool MonsterTrapHit(int monsterId, int mindam, int maxdam, int dist, MissileID t, DamageType damageType, bool shift) { - auto &monster = Monsters[monsterId]; + Monster &monster = Monsters[monsterId]; if (!monster.isPossibleToHit() || monster.isImmune(t, damageType)) return false; @@ -1246,7 +1246,7 @@ void AddBerserk(Missile &missile, AddMissileParameter ¶meter) parameter.dst, 0, 5); if (targetMonsterPosition) { - auto &monster = Monsters[std::abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1]; + Monster &monster = Monsters[std::abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1]; Player &player = *missile.sourcePlayer(); const int slvl = player.GetSpellLevel(SpellID::Berserk); monster.flags |= MFLAG_BERSERK | MFLAG_GOLEM; @@ -2203,7 +2203,7 @@ void AddGenericMagicMissile(Missile &missile, AddMissileParameter ¶meter) missile.var2 = missile.position.start.y; missile._mlid = AddLight(missile.position.start, 8); if (missile._micaster != TARGET_MONSTERS && missile._misource > 0) { - auto &monster = Monsters[missile._misource]; + Monster &monster = Monsters[missile._misource]; if (monster.type().type == MT_SUCCUBUS) SetMissAnim(missile, MissileGraphicID::BloodStar); if (monster.type().type == MT_SNOWWICH) @@ -2283,7 +2283,7 @@ void AddStoneCurse(Missile &missile, AddMissileParameter ¶meter) return false; } - auto &monster = Monsters[monsterId]; + Monster &monster = Monsters[monsterId]; if (IsAnyOf(monster.type().type, MT_GOLEM, MT_DIABLO, MT_NAKRUL)) { return false; @@ -2304,7 +2304,7 @@ void AddStoneCurse(Missile &missile, AddMissileParameter ¶meter) // Petrify the targeted monster int monsterId = std::abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1; - auto &monster = Monsters[monsterId]; + Monster &monster = Monsters[monsterId]; if (monster.mode == MonsterMode::Petrified) { // Monster is already petrified and StoneCurse doesn't stack @@ -2584,7 +2584,7 @@ void AddInferno(Missile &missile, AddMissileParameter ¶meter) int i = GenerateRnd(Players[missile._misource].getCharacterLevel()) + GenerateRnd(2); missile._midam = 8 * i + 16 + ((8 * i + 16) / 2); } else { - auto &monster = Monsters[missile._misource]; + Monster &monster = Monsters[missile._misource]; missile._midam = monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1); } } @@ -3006,7 +3006,7 @@ void ProcessFireball(Missile &missile) int maxDam = missile._midam; if (missile._micaster != TARGET_MONSTERS) { - auto &monster = Monsters[missile._misource]; + Monster &monster = Monsters[missile._misource]; minDam = monster.minDamage; maxDam = monster.maxDamage; } @@ -3298,7 +3298,7 @@ void ProcessLightningControl(Missile &missile) // BUGFIX: damage of missile should be encoded in missile struct; player can be dead/have left the game before missile arrives. dam = (GenerateRnd(2) + GenerateRnd(Players[missile._misource].getCharacterLevel()) + 2) << 6; } else { - auto &monster = Monsters[missile._misource]; + Monster &monster = Monsters[missile._misource]; dam = 2 * (monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1)); } @@ -3649,7 +3649,7 @@ void ProcessTeleport(Missile &missile) void ProcessStoneCurse(Missile &missile) { missile._mirange--; - auto &monster = Monsters[missile.var2]; + Monster &monster = Monsters[missile.var2]; if (monster.hitPoints == 0 && missile._miAnimType != MissileGraphicID::StoneCurseShatter) { missile._mimfnum = 0; missile._miDrawFlag = true; @@ -3689,7 +3689,7 @@ void ProcessApocalypseBoom(Missile &missile) void ProcessRhino(Missile &missile) { int monst = missile._misource; - auto &monster = Monsters[monst]; + Monster &monster = Monsters[monst]; if (monster.mode != MonsterMode::Charge) { missile._miDelFlag = true; return; diff --git a/Source/monster.cpp b/Source/monster.cpp index bb27dc8ad6e..b51d53c60df 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -256,7 +256,7 @@ void PlaceGroup(size_t typeIndex, size_t num, Monster *leader = nullptr, bool le while (placed != 0) { ActiveMonsterCount--; placed--; - const auto &position = Monsters[ActiveMonsterCount].position.tile; + const Point &position = Monsters[ActiveMonsterCount].position.tile; dMonster[position.x][position.y] = 0; } @@ -291,7 +291,7 @@ void PlaceGroup(size_t typeIndex, size_t num, Monster *leader = nullptr, bool le PlaceMonster(ActiveMonsterCount, typeIndex, { xp, yp }); if (leader != nullptr) { - auto &minion = Monsters[ActiveMonsterCount]; + Monster &minion = Monsters[ActiveMonsterCount]; minion.maxHitPoints *= 2; minion.hitPoints = minion.maxHitPoints; minion.intelligence = leader->intelligence; @@ -333,7 +333,7 @@ size_t GetMonsterTypeIndex(_monster_id type) void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize) { - auto &monster = Monsters[ActiveMonsterCount]; + Monster &monster = Monsters[ActiveMonsterCount]; const auto &uniqueMonsterData = UniqueMonstersData[static_cast(uniqindex)]; int count = 0; @@ -568,7 +568,7 @@ void LoadDiabMonsts() void DeleteMonster(size_t activeIndex) { - const auto &monster = Monsters[ActiveMonsters[activeIndex]]; + const Monster &monster = Monsters[ActiveMonsters[activeIndex]]; if ((monster.flags & MFLAG_BERSERK) != 0) { AddUnLight(monster.lightId); } @@ -1420,7 +1420,7 @@ bool MonsterGotHit(Monster &monster) void ReleaseMinions(const Monster &leader) { for (size_t i = 0; i < ActiveMonsterCount; i++) { - auto &minion = Monsters[ActiveMonsters[i]]; + Monster &minion = Monsters[ActiveMonsters[i]]; if (minion.leaderRelation == LeaderRelation::Leashed && minion.getLeader() == &leader) { minion.setLeader(nullptr); } @@ -2209,7 +2209,7 @@ void FallenAi(Monster &monster) if (m <= 0) continue; - auto &otherMonster = Monsters[m - 1]; + Monster &otherMonster = Monsters[m - 1]; if (otherMonster.ai != MonsterAIID::Fallen) continue; @@ -3494,7 +3494,7 @@ void WeakenNaKrul() if (currlevel != 24 || static_cast(UberDiabloMonsterIndex) >= ActiveMonsterCount) return; - auto &monster = Monsters[UberDiabloMonsterIndex]; + Monster &monster = Monsters[UberDiabloMonsterIndex]; PlayEffect(monster, MonsterSound::Death); monster.armorClass -= 50; int hp = monster.maxHitPoints / 2; @@ -3961,7 +3961,7 @@ void GolumAi(Monster &golem) } if ((golem.flags & MFLAG_NO_ENEMY) == 0) { - auto &enemy = Monsters[golem.enemy]; + Monster &enemy = Monsters[golem.enemy]; int mex = golem.position.tile.x - enemy.position.future.x; int mey = golem.position.tile.y - enemy.position.future.y; golem.direction = GetDirection(golem.position.tile, enemy.position.tile); @@ -4008,7 +4008,7 @@ void GolumAi(Monster &golem) void DeleteMonsterList() { for (int i = 0; i < MAX_PLRS; i++) { - auto &golem = Monsters[i]; + Monster &golem = Monsters[i]; if (!golem.isInvalid) continue; @@ -4377,7 +4377,7 @@ void PrintMonstHistory(int mt) void PrintUniqueHistory() { - auto &monster = Monsters[pcursmonst]; + Monster &monster = Monsters[pcursmonst]; if (*sgOptions.Gameplay.showMonsterType) { AddPanelString(fmt::format(fmt::runtime(_("Type: {:s}")), GetMonsterTypeText(monster.data()))); } @@ -4426,7 +4426,7 @@ void PlayEffect(Monster &monster, MonsterSound mode) void MissToMonst(Missile &missile, Point position) { assert(static_cast(missile._misource) < MaxMonsters); - auto &monster = Monsters[missile._misource]; + Monster &monster = Monsters[missile._misource]; Point oldPosition = missile.position.tile; monster.occupyTile(position, false); @@ -4500,7 +4500,7 @@ Monster *FindUniqueMonster(UniqueMonsterType monsterType) { for (size_t i = 0; i < ActiveMonsterCount; i++) { int monsterId = ActiveMonsters[i]; - auto &monster = Monsters[monsterId]; + Monster &monster = Monsters[monsterId]; if (monster.uniqueType == monsterType) return &monster; } diff --git a/Source/msg.cpp b/Source/msg.cpp index 5019b182ffb..f3d90d0095a 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -758,7 +758,7 @@ void DeltaLeaveSync(uint8_t bLevel) for (size_t i = 0; i < ActiveMonsterCount; i++) { const unsigned ma = ActiveMonsters[i]; - auto &monster = Monsters[ma]; + Monster &monster = Monsters[ma]; if (monster.hitPoints == 0) continue; DMonsterStr &delta = deltaLevel.monster[ma]; @@ -1818,7 +1818,7 @@ size_t OnMonstDamage(const TCmd *pCmd, Player &player) if (gbBufferMsgs != 1) { if (&player != MyPlayer) { if (player.isOnActiveLevel() && monsterIdx < MaxMonsters) { - auto &monster = Monsters[monsterIdx]; + Monster &monster = Monsters[monsterIdx]; monster.tag(player); if (monster.hitPoints > 0) { monster.hitPoints -= SDL_SwapLE32(message.dwDam); @@ -2700,7 +2700,7 @@ void DeltaLoadLevel() if (deltaLevel.monster[i].position.x == 0xFF) continue; - auto &monster = Monsters[i]; + Monster &monster = Monsters[i]; M_ClearSquares(monster); { const WorldTilePosition position = deltaLevel.monster[i].position; diff --git a/Source/objects.cpp b/Source/objects.cpp index da47c4640c6..2cd1d279b3b 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3129,7 +3129,7 @@ void OperateBookcase(Object &bookcase, bool sendmsg, bool sendLootMsg) CreateTypeItem(bookcase.position, false, ItemType::Misc, IMISC_BOOK, sendLootMsg, false); if (Quests[Q_ZHAR].IsAvailable()) { - auto &zhar = Monsters[MAX_PLRS]; + Monster &zhar = Monsters[MAX_PLRS]; if (zhar.mode == MonsterMode::Stand // prevents playing the "angry" message for the second time if zhar got aggroed by losing vision and talking again && zhar.uniqueType == UniqueMonsterType::Zhar && zhar.activeForTicks == UINT8_MAX diff --git a/Source/player.cpp b/Source/player.cpp index 5d80cc54812..fdd78b0a38f 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -329,7 +329,7 @@ void DeadItem(Player &player, Item &&itm, Displacement direction) int DropGold(Player &player, int amount, bool skipFullStacks) { for (int i = 0; i < player._pNumInv && amount > 0; i++) { - auto &item = player.InvList[i]; + Item &item = player.InvList[i]; if (item._itype != ItemType::Gold || (skipFullStacks && item._ivalue == MaxGold)) continue; @@ -1779,7 +1779,7 @@ void Player::RestorePartialMana() void Player::ReadySpellFromEquipment(inv_body_loc bodyLocation, bool forceSpell) { - auto &item = InvBody[bodyLocation]; + Item &item = InvBody[bodyLocation]; if (item._itype == ItemType::Staff && IsValidSpell(item._iSpell) && item._iCharges > 0 && item._iStatFlag) { if (forceSpell || _pRSpell == SpellID::Invalid || _pRSplType == SpellType::Invalid) { _pRSpell = item._iSpell; @@ -1877,19 +1877,19 @@ void Player::UpdatePreviewCelSprite(_cmd_id cmdId, Point point, uint16_t wParam1 switch (cmdId) { case _cmd_id::CMD_RATTACKID: { - auto &monster = Monsters[wParam1]; + Monster &monster = Monsters[wParam1]; dir = GetDirection(position.future, monster.position.future); graphic = player_graphic::Attack; break; } case _cmd_id::CMD_SPELLID: { - auto &monster = Monsters[wParam1]; + Monster &monster = Monsters[wParam1]; dir = GetDirection(position.future, monster.position.future); graphic = GetPlayerGraphicForSpell(static_cast(wParam2)); break; } case _cmd_id::CMD_ATTACKID: { - auto &monster = Monsters[wParam1]; + Monster &monster = Monsters[wParam1]; point = monster.position.future; minimalWalkDistance = 2; if (!CanTalkToMonst(monster)) { @@ -2674,7 +2674,7 @@ StartPlayerKill(Player &player, DeathReason deathReason) if (&player != MyPlayer && dropItems) { // Ensure that items are removed for remote players // The dropped items will be synced seperatly (by the remote client) - for (auto &item : player.InvBody) { + for (Item &item : player.InvBody) { item.clear(); } CalcPlrInv(player, false); @@ -2728,7 +2728,7 @@ StartPlayerKill(Player &player, DeathReason deathReason) } if (dropItems) { Direction pdd = player._pdir; - for (auto &item : player.InvBody) { + for (Item &item : player.InvBody) { pdd = Left(pdd); DeadItem(player, item.pop(), Displacement(pdd)); } diff --git a/Source/sync.cpp b/Source/sync.cpp index 4491ec7bcf6..d758212d667 100644 --- a/Source/sync.cpp +++ b/Source/sync.cpp @@ -26,7 +26,7 @@ void SyncOneMonster() { for (size_t i = 0; i < ActiveMonsterCount; i++) { const unsigned m = ActiveMonsters[i]; - auto &monster = Monsters[m]; + Monster &monster = Monsters[m]; sgnMonsterPriority[m] = MyPlayer->position.tile.ManhattanDistance(monster.position.tile); if (monster.activeForTicks == 0) { sgnMonsterPriority[m] += 0x1000; @@ -38,7 +38,7 @@ void SyncOneMonster() void SyncMonsterPos(TSyncMonster &monsterSync, int ndx) { - auto &monster = Monsters[ndx]; + Monster &monster = Monsters[ndx]; monsterSync._mndx = ndx; monsterSync._mx = monster.position.tile.x; monsterSync._my = monster.position.tile.y;