Browse Source

Splitting CheckInvPaste() into smaller functions (#6984)

pull/7097/head
matheusgomes28 2 years ago committed by GitHub
parent
commit
7848ab731e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Source/control.cpp
  2. 6
      Source/controls/plrctrls.cpp
  3. 2
      Source/controls/touch/renderers.cpp
  4. 4
      Source/diablo.cpp
  5. 459
      Source/inv.cpp
  6. 2
      Source/loadsave.cpp
  7. 22
      Source/missiles.cpp
  8. 24
      Source/monster.cpp
  9. 6
      Source/msg.cpp
  10. 2
      Source/objects.cpp
  11. 14
      Source/player.cpp
  12. 4
      Source/sync.cpp

2
Source/control.cpp

@ -1213,7 +1213,7 @@ void DrawInfoBox(const Surface &out)
GetObjectStr(*ObjectUnderCursor); GetObjectStr(*ObjectUnderCursor);
if (pcursmonst != -1) { if (pcursmonst != -1) {
if (leveltype != DTYPE_TOWN) { if (leveltype != DTYPE_TOWN) {
const auto &monster = Monsters[pcursmonst]; const Monster &monster = Monsters[pcursmonst];
InfoColor = UiFlags::ColorWhite; InfoColor = UiFlags::ColorWhite;
InfoString = monster.name(); InfoString = monster.name();
if (monster.isUnique()) { if (monster.isUnique()) {

6
Source/controls/plrctrls.cpp

@ -165,7 +165,7 @@ void FindItemOrObject()
continue; continue;
} }
auto &item = Items[itemId]; Item &item = Items[itemId];
if (item.isEmpty() || item._iSelFlag == 0) { if (item.isEmpty() || item._iSelFlag == 0) {
continue; continue;
} }
@ -266,7 +266,7 @@ void FindRangedTarget()
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
int mi = ActiveMonsters[i]; int mi = ActiveMonsters[i];
const auto &monster = Monsters[mi]; const Monster &monster = Monsters[mi];
if (!CanTargetMonster(monster)) if (!CanTargetMonster(monster))
continue; continue;
@ -332,7 +332,7 @@ void FindMeleeTarget()
if (dMonster[dx][dy] != 0) { if (dMonster[dx][dy] != 0) {
const int mi = std::abs(dMonster[dx][dy]) - 1; const int mi = std::abs(dMonster[dx][dy]) - 1;
const auto &monster = Monsters[mi]; const Monster &monster = Monsters[mi];
if (CanTargetMonster(monster)) { if (CanTargetMonster(monster)) {
const bool newCanTalk = CanTalkToMonst(monster); const bool newCanTalk = CanTalkToMonst(monster);
if (pcursmonst != -1 && !canTalk && newCanTalk) if (pcursmonst != -1 && !canTalk && newCanTalk)

2
Source/controls/touch/renderers.cpp

@ -438,7 +438,7 @@ VirtualGamepadButtonType PrimaryActionButtonRenderer::GetTownButtonType()
VirtualGamepadButtonType PrimaryActionButtonRenderer::GetDungeonButtonType() VirtualGamepadButtonType PrimaryActionButtonRenderer::GetDungeonButtonType()
{ {
if (pcursmonst != -1) { if (pcursmonst != -1) {
const auto &monster = Monsters[pcursmonst]; const Monster &monster = Monsters[pcursmonst];
if (M_Talker(monster) || monster.talkMsg != TEXT_NONE) if (M_Talker(monster) || monster.talkMsg != TEXT_NONE)
return GetTalkButtonType(virtualPadButton->isHeld); return GetTalkButtonType(virtualPadButton->isHeld);
} }

4
Source/diablo.cpp

@ -1391,7 +1391,7 @@ void UnstuckChargers()
} }
} }
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
auto &monster = Monsters[ActiveMonsters[i]]; Monster &monster = Monsters[ActiveMonsters[i]];
if (monster.mode == MonsterMode::Charge) if (monster.mode == MonsterMode::Charge)
monster.mode = MonsterMode::Stand; monster.mode = MonsterMode::Stand;
} }
@ -1400,7 +1400,7 @@ void UnstuckChargers()
void UpdateMonsterLights() void UpdateMonsterLights()
{ {
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
auto &monster = Monsters[ActiveMonsters[i]]; Monster &monster = Monsters[ActiveMonsters[i]];
if ((monster.flags & MFLAG_BERSERK) != 0) { if ((monster.flags & MFLAG_BERSERK) != 0) {
int lightRadius = leveltype == DTYPE_NEST ? 9 : 3; int lightRadius = leveltype == DTYPE_NEST ? 9 : 3;

459
Source/inv.cpp

@ -325,237 +325,278 @@ int FindTargetSlotUnderItemCursor(Point cursorPosition, Size itemSize)
return NUM_XY_SLOTS; 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); const inv_body_loc bodyLocation = [&slot](item_equip_type location) {
switch (location) {
int slot = FindTargetSlotUnderItemCursor(cursorPosition, itemSize); case ILOC_HELM:
if (slot == NUM_XY_SLOTS) return INVLOC_HEAD;
return; case ILOC_RING:
return (slot == SLOTXY_RING_LEFT ? INVLOC_RING_LEFT : INVLOC_RING_RIGHT);
item_equip_type il = ILOC_UNEQUIPABLE; case ILOC_AMULET:
if (slot == SLOTXY_HEAD) return INVLOC_AMULET;
il = ILOC_HELM; case ILOC_ARMOR:
if (slot == SLOTXY_RING_LEFT || slot == SLOTXY_RING_RIGHT) return INVLOC_CHEST;
il = ILOC_RING; default:
if (slot == SLOTXY_AMULET) app_fatal("Unexpected equipment type");
il = ILOC_AMULET; }
if (slot == SLOTXY_HAND_LEFT || slot == SLOTXY_HAND_RIGHT) }(location);
il = ILOC_ONEHAND; const Item previouslyEquippedItem = player.InvBody[slot];
if (slot == SLOTXY_CHEST) ChangeEquipment(player, bodyLocation, player.HoldItem.pop(), &player == MyPlayer);
il = ILOC_ARMOR; if (!previouslyEquippedItem.isEmpty()) {
if (slot >= SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) player.HoldItem = previouslyEquippedItem;
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<unsigned>(slot - SLOTXY_INV_FIRST);
for (unsigned rowOffset = 0; rowOffset < static_cast<unsigned>(itemSize.height * InventorySizeInSlots.width); rowOffset += InventorySizeInSlots.width) {
for (unsigned columnOffset = 0; columnOffset < static_cast<unsigned>(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;
} }
}
if (IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT) && !player.CanUseItem(player.HoldItem)) { void ChangeEquippedItem(Player &player, uint8_t slot)
player.Say(HeroSpeech::ICantUseThisYet); {
return; 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)) const bool pasteIntoSelectedHand = (player.InvBody[otherHand].isEmpty() || player.InvBody[otherHand]._iClass != player.HoldItem._iClass)
return; || (player._pClass == HeroClass::Bard && player.InvBody[otherHand]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON);
if (&player == MyPlayer) const bool dequipTwoHandedWeapon = (!player.InvBody[otherHand].isEmpty() && player.GetItemLocation(player.InvBody[otherHand]) == ILOC_TWOHAND);
PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]);
switch (il) { const inv_body_loc pasteHand = pasteIntoSelectedHand ? selectedHand : otherHand;
case ILOC_HELM: const Item previouslyEquippedItem = dequipTwoHandedWeapon ? player.InvBody[otherHand] : player.InvBody[pasteHand];
case ILOC_RING: if (dequipTwoHandedWeapon) {
case ILOC_AMULET: RemoveEquipment(player, otherHand, false);
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;
} }
case ILOC_ONEHAND: { ChangeEquipment(player, pasteHand, player.HoldItem.pop(), &player == MyPlayer);
inv_body_loc selectedHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_LEFT : INVLOC_HAND_RIGHT; if (!previouslyEquippedItem.isEmpty()) {
inv_body_loc otherHand = slot == SLOTXY_HAND_LEFT ? INVLOC_HAND_RIGHT : INVLOC_HAND_LEFT; player.HoldItem = previouslyEquippedItem;
}
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);
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; if (locationToUnequip == INVLOC_HAND_RIGHT) {
Item previouslyEquippedItem = dequipTwoHandedWeapon ? player.InvBody[otherHand] : player.InvBody[pasteHand]; RemoveEquipment(player, INVLOC_HAND_RIGHT, false);
if (dequipTwoHandedWeapon) { } else {
RemoveEquipment(player, otherHand, false); 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()) { if (!previouslyEquippedItem.isEmpty()) {
player.HoldItem = previouslyEquippedItem; 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) { int8_t CheckOverlappingItems(int slot, const Player &player, Size itemSize)
RemoveEquipment(player, INVLOC_HAND_RIGHT, false); {
} else { // check that the item we're pasting only overlaps one other item (or is going into empty space)
// CMD_CHANGEPLRITEMS will eventually be sent for the left hand const unsigned originCell = static_cast<unsigned>(slot - SLOTXY_INV_FIRST);
player.InvBody[INVLOC_HAND_LEFT].clear();
int8_t overlappingId = 0;
for (unsigned rowOffset = 0; rowOffset < static_cast<unsigned>(itemSize.height * InventorySizeInSlots.width); rowOffset += InventorySizeInSlots.width) {
for (unsigned columnOffset = 0; columnOffset < static_cast<unsigned>(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()) { return overlappingId;
Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_LEFT]; }
ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem.pop(), &player == MyPlayer);
if (!previouslyEquippedItem.isEmpty()) { int8_t GetPrevItemId(int slot, const Player &player, const Size &itemSize)
player.HoldItem = previouslyEquippedItem; {
} if (player.HoldItem._itype != ItemType::Gold)
} else { return CheckOverlappingItems(slot, player, itemSize);
Item previouslyEquippedItem = player.InvBody[INVLOC_HAND_RIGHT]; int8_t item_cell_begin = player.InvGrid[slot - SLOTXY_INV_FIRST];
RemoveEquipment(player, INVLOC_HAND_RIGHT, false); if (item_cell_begin == 0)
ChangeEquipment(player, INVLOC_HAND_LEFT, player.HoldItem, &player == MyPlayer); return 0;
player.HoldItem = previouslyEquippedItem; if (item_cell_begin <= 0)
} return -item_cell_begin;
break; if (player.InvList[item_cell_begin - 1]._itype != ItemType::Gold)
case ILOC_UNEQUIPABLE: return item_cell_begin;
if (player.HoldItem._itype == ItemType::Gold && it == 0) { return 0;
int ii = slot - SLOTXY_INV_FIRST; }
if (player.InvGrid[ii] > 0) {
int invIndex = player.InvGrid[ii] - 1; bool ChangeInvItem(Player &player, int slot, Size itemSize)
int gt = player.InvList[invIndex]._ivalue; {
int ig = player.HoldItem._ivalue + gt; int8_t prevItemId = GetPrevItemId(slot, player, itemSize);
if (ig <= MaxGold) { if (prevItemId < 0) return false;
player.InvList[invIndex]._ivalue = ig;
SetPlrHandGoldCurs(player.InvList[invIndex]); if (player.HoldItem._itype == ItemType::Gold && prevItemId == 0) {
player._pGold += player.HoldItem._ivalue; const int ii = slot - SLOTXY_INV_FIRST;
player.HoldItem.clear(); if (player.InvGrid[ii] > 0) {
} else { const int invIndex = player.InvGrid[ii] - 1;
ig = MaxGold - gt; const int gt = player.InvList[invIndex]._ivalue;
player._pGold += ig; int ig = player.HoldItem._ivalue + gt;
player.HoldItem._ivalue -= ig; if (ig <= MaxGold) {
SetPlrHandGoldCurs(player.HoldItem); player.InvList[invIndex]._ivalue = ig;
player.InvList[invIndex]._ivalue = MaxGold; SetPlrHandGoldCurs(player.InvList[invIndex]);
player.InvList[invIndex]._iCurs = ICURS_GOLD_LARGE;
}
} else {
int invIndex = player._pNumInv;
player._pGold += player.HoldItem._ivalue; player._pGold += player.HoldItem._ivalue;
player.InvList[invIndex] = player.HoldItem.pop(); player.HoldItem.clear();
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;
} else { } else {
int invIndex = it - 1; ig = MaxGold - gt;
if (player.HoldItem._itype == ItemType::Gold) player._pGold += ig;
player._pGold += player.HoldItem._ivalue; player.HoldItem._ivalue -= ig;
std::swap(player.InvList[invIndex], player.HoldItem); SetPlrHandGoldCurs(player.HoldItem);
if (player.HoldItem._itype == ItemType::Gold) player.InvList[invIndex]._ivalue = MaxGold;
player._pGold = CalculateGold(player); player.InvList[invIndex]._iCurs = ICURS_GOLD_LARGE;
for (auto &itemIndex : player.InvGrid) {
if (itemIndex == it)
itemIndex = 0;
if (itemIndex == -it)
itemIndex = 0;
}
} }
} else {
AddItemToInvGrid(player, slot - SLOTXY_INV_FIRST, it, itemSize, &player == MyPlayer); const int invIndex = player._pNumInv;
player._pGold += player.HoldItem._ivalue;
player.InvList[invIndex] = player.HoldItem.pop();
player._pNumInv++;
player.InvGrid[ii] = player._pNumInv;
} }
break; if (&player == MyPlayer) {
case ILOC_BELT: { NetSendCmdChInvItem(false, ii);
int ii = slot - SLOTXY_BELT_FIRST; }
if (player.SpdList[ii].isEmpty()) { } else {
player.SpdList[ii] = player.HoldItem.pop(); if (prevItemId == 0) {
player.InvList[player._pNumInv] = player.HoldItem.pop();
player._pNumInv++;
prevItemId = player._pNumInv;
} else { } 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) if (player.HoldItem._itype == ItemType::Gold)
player._pGold = CalculateGold(player); 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); if (player._pmode > PM_WALK_SIDEWAYS)
} break; 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_NONE:
case ILOC_INVALID: case ILOC_INVALID:
break; break;
} }
CalcPlrInv(player, true); CalcPlrInv(player, true);
if (&player == MyPlayer) { if (&player == MyPlayer) {
PlaySFX(ItemInvSnds[ItemCAnimTbl[player.HoldItem._iCurs]]);
NewCursor(player.HoldItem); NewCursor(player.HoldItem);
} }
} }
@ -917,7 +958,7 @@ void CheckQuestItem(Player &player, Item &questItem)
void CleanupItems(int ii) void CleanupItems(int ii)
{ {
auto &item = Items[ii]; Item &item = Items[ii];
dItem[item.position.x][item.position.y] = 0; dItem[item.position.x][item.position.y] = 0;
if (CornerStone.isAvailable() && item.position == CornerStone.position) { 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; 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 // calc item offsets for weapons/armor smaller than 2x3 slots
if (IsAnyOf(slot, INVLOC_HAND_LEFT, INVLOC_HAND_RIGHT, INVLOC_CHEST)) { 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; return false;
} }
for (auto &beltItem : player.SpdList) { for (Item &beltItem : player.SpdList) {
if (beltItem.isEmpty()) { if (beltItem.isEmpty()) {
if (persistItem) { if (persistItem) {
beltItem = item; 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) void CheckInvSwap(Player &player, const Item &item, int invGridIndex)
{ {
auto itemSize = GetInventorySize(item); Size itemSize = GetInventorySize(item);
const int pitch = 10; const int pitch = 10;
int invListIndex = [&]() -> int { int invListIndex = [&]() -> int {
@ -1536,7 +1577,7 @@ void CheckInvSwap(Player &player, const Item &item, int invGridIndex)
}(); }();
if (invListIndex < player._pNumInv) { if (invListIndex < player._pNumInv) {
for (auto &itemIndex : player.InvGrid) { for (int8_t &itemIndex : player.InvGrid) {
if (itemIndex == invListIndex) if (itemIndex == invListIndex)
itemIndex = 0; itemIndex = 0;
if (itemIndex == -invListIndex) if (itemIndex == -invListIndex)
@ -1615,7 +1656,7 @@ void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld)
void InvGetItem(Player &player, int ii) void InvGetItem(Player &player, int ii)
{ {
auto &item = Items[ii]; Item &item = Items[ii];
CloseGoldDrop(); CloseGoldDrop();
if (dItem[item.position.x][item.position.y] == 0) 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) int FindGetItem(uint32_t iseed, _item_indexes idx, uint16_t createInfo)
{ {
for (uint8_t i = 0; i < ActiveItemCount; i++) { for (uint8_t i = 0; i < ActiveItemCount; i++) {
auto &item = Items[ActiveItems[i]]; Item &item = Items[ActiveItems[i]];
if (item.keyAttributesMatch(iseed, idx, createInfo)) { if (item.keyAttributesMatch(iseed, idx, createInfo)) {
return i; return i;
} }
@ -1954,7 +1995,7 @@ void ConsumeScroll(Player &player)
{ {
const SpellID spellId = player.executedSpell.spellId; 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); return item.isScrollOf(spellId) || item.isRuneOf(spellId);
}; };
@ -1995,7 +2036,7 @@ bool CanUseScroll(Player &player, SpellID spell)
void ConsumeStaffCharge(Player &player) void ConsumeStaffCharge(Player &player)
{ {
auto &staff = player.InvBody[INVLOC_HAND_LEFT]; Item &staff = player.InvBody[INVLOC_HAND_LEFT];
if (!CanUseStaff(staff, player.executedSpell.spellId)) if (!CanUseStaff(staff, player.executedSpell.spellId))
return; return;
@ -2201,7 +2242,7 @@ void DoTelekinesis()
if (pcursitem != -1) if (pcursitem != -1)
NetSendCmdGItem(true, CMD_REQUESTAGITEM, *MyPlayer, pcursitem); NetSendCmdGItem(true, CMD_REQUESTAGITEM, *MyPlayer, pcursitem);
if (pcursmonst != -1) { if (pcursmonst != -1) {
auto &monter = Monsters[pcursmonst]; Monster &monter = Monsters[pcursmonst];
if (!M_Talker(monter) && monter.talkMsg == TEXT_NONE) if (!M_Talker(monter) && monter.talkMsg == TEXT_NONE)
NetSendCmdParam1(true, CMD_KNOCKBACK, pcursmonst); NetSendCmdParam1(true, CMD_KNOCKBACK, pcursmonst);
} }
@ -2222,7 +2263,7 @@ int CalculateGold(Player &player)
Size GetInventorySize(const Item &item) 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 }; return { size.width / InventorySlotSizeInPixels.width, size.height / InventorySlotSizeInPixels.height };
} }

2
Source/loadsave.cpp

@ -688,7 +688,7 @@ void SyncPackSize(Monster &leader)
leader.packSize = 0; leader.packSize = 0;
for (size_t i = 0; i < ActiveMonsterCount; i++) { 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) if (minion.leaderRelation == LeaderRelation::Leashed && minion.getLeader() == &leader)
leader.packSize++; leader.packSize++;
} }

22
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) 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)) if (!monster.isPossibleToHit() || monster.isImmune(t, damageType))
return false; 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) 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)) if (!monster.isPossibleToHit() || monster.isImmune(t, damageType))
return false; return false;
@ -1246,7 +1246,7 @@ void AddBerserk(Missile &missile, AddMissileParameter &parameter)
parameter.dst, 0, 5); parameter.dst, 0, 5);
if (targetMonsterPosition) { 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(); Player &player = *missile.sourcePlayer();
const int slvl = player.GetSpellLevel(SpellID::Berserk); const int slvl = player.GetSpellLevel(SpellID::Berserk);
monster.flags |= MFLAG_BERSERK | MFLAG_GOLEM; monster.flags |= MFLAG_BERSERK | MFLAG_GOLEM;
@ -2203,7 +2203,7 @@ void AddGenericMagicMissile(Missile &missile, AddMissileParameter &parameter)
missile.var2 = missile.position.start.y; missile.var2 = missile.position.start.y;
missile._mlid = AddLight(missile.position.start, 8); missile._mlid = AddLight(missile.position.start, 8);
if (missile._micaster != TARGET_MONSTERS && missile._misource > 0) { if (missile._micaster != TARGET_MONSTERS && missile._misource > 0) {
auto &monster = Monsters[missile._misource]; Monster &monster = Monsters[missile._misource];
if (monster.type().type == MT_SUCCUBUS) if (monster.type().type == MT_SUCCUBUS)
SetMissAnim(missile, MissileGraphicID::BloodStar); SetMissAnim(missile, MissileGraphicID::BloodStar);
if (monster.type().type == MT_SNOWWICH) if (monster.type().type == MT_SNOWWICH)
@ -2283,7 +2283,7 @@ void AddStoneCurse(Missile &missile, AddMissileParameter &parameter)
return false; return false;
} }
auto &monster = Monsters[monsterId]; Monster &monster = Monsters[monsterId];
if (IsAnyOf(monster.type().type, MT_GOLEM, MT_DIABLO, MT_NAKRUL)) { if (IsAnyOf(monster.type().type, MT_GOLEM, MT_DIABLO, MT_NAKRUL)) {
return false; return false;
@ -2304,7 +2304,7 @@ void AddStoneCurse(Missile &missile, AddMissileParameter &parameter)
// Petrify the targeted monster // Petrify the targeted monster
int monsterId = std::abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1; int monsterId = std::abs(dMonster[targetMonsterPosition->x][targetMonsterPosition->y]) - 1;
auto &monster = Monsters[monsterId]; Monster &monster = Monsters[monsterId];
if (monster.mode == MonsterMode::Petrified) { if (monster.mode == MonsterMode::Petrified) {
// Monster is already petrified and StoneCurse doesn't stack // Monster is already petrified and StoneCurse doesn't stack
@ -2584,7 +2584,7 @@ void AddInferno(Missile &missile, AddMissileParameter &parameter)
int i = GenerateRnd(Players[missile._misource].getCharacterLevel()) + GenerateRnd(2); int i = GenerateRnd(Players[missile._misource].getCharacterLevel()) + GenerateRnd(2);
missile._midam = 8 * i + 16 + ((8 * i + 16) / 2); missile._midam = 8 * i + 16 + ((8 * i + 16) / 2);
} else { } else {
auto &monster = Monsters[missile._misource]; Monster &monster = Monsters[missile._misource];
missile._midam = monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1); missile._midam = monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1);
} }
} }
@ -3006,7 +3006,7 @@ void ProcessFireball(Missile &missile)
int maxDam = missile._midam; int maxDam = missile._midam;
if (missile._micaster != TARGET_MONSTERS) { if (missile._micaster != TARGET_MONSTERS) {
auto &monster = Monsters[missile._misource]; Monster &monster = Monsters[missile._misource];
minDam = monster.minDamage; minDam = monster.minDamage;
maxDam = monster.maxDamage; 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. // 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; dam = (GenerateRnd(2) + GenerateRnd(Players[missile._misource].getCharacterLevel()) + 2) << 6;
} else { } else {
auto &monster = Monsters[missile._misource]; Monster &monster = Monsters[missile._misource];
dam = 2 * (monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1)); dam = 2 * (monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1));
} }
@ -3649,7 +3649,7 @@ void ProcessTeleport(Missile &missile)
void ProcessStoneCurse(Missile &missile) void ProcessStoneCurse(Missile &missile)
{ {
missile._mirange--; missile._mirange--;
auto &monster = Monsters[missile.var2]; Monster &monster = Monsters[missile.var2];
if (monster.hitPoints == 0 && missile._miAnimType != MissileGraphicID::StoneCurseShatter) { if (monster.hitPoints == 0 && missile._miAnimType != MissileGraphicID::StoneCurseShatter) {
missile._mimfnum = 0; missile._mimfnum = 0;
missile._miDrawFlag = true; missile._miDrawFlag = true;
@ -3689,7 +3689,7 @@ void ProcessApocalypseBoom(Missile &missile)
void ProcessRhino(Missile &missile) void ProcessRhino(Missile &missile)
{ {
int monst = missile._misource; int monst = missile._misource;
auto &monster = Monsters[monst]; Monster &monster = Monsters[monst];
if (monster.mode != MonsterMode::Charge) { if (monster.mode != MonsterMode::Charge) {
missile._miDelFlag = true; missile._miDelFlag = true;
return; return;

24
Source/monster.cpp

@ -256,7 +256,7 @@ void PlaceGroup(size_t typeIndex, size_t num, Monster *leader = nullptr, bool le
while (placed != 0) { while (placed != 0) {
ActiveMonsterCount--; ActiveMonsterCount--;
placed--; placed--;
const auto &position = Monsters[ActiveMonsterCount].position.tile; const Point &position = Monsters[ActiveMonsterCount].position.tile;
dMonster[position.x][position.y] = 0; 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 }); PlaceMonster(ActiveMonsterCount, typeIndex, { xp, yp });
if (leader != nullptr) { if (leader != nullptr) {
auto &minion = Monsters[ActiveMonsterCount]; Monster &minion = Monsters[ActiveMonsterCount];
minion.maxHitPoints *= 2; minion.maxHitPoints *= 2;
minion.hitPoints = minion.maxHitPoints; minion.hitPoints = minion.maxHitPoints;
minion.intelligence = leader->intelligence; minion.intelligence = leader->intelligence;
@ -333,7 +333,7 @@ size_t GetMonsterTypeIndex(_monster_id type)
void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize) void PlaceUniqueMonst(UniqueMonsterType uniqindex, size_t minionType, int bosspacksize)
{ {
auto &monster = Monsters[ActiveMonsterCount]; Monster &monster = Monsters[ActiveMonsterCount];
const auto &uniqueMonsterData = UniqueMonstersData[static_cast<size_t>(uniqindex)]; const auto &uniqueMonsterData = UniqueMonstersData[static_cast<size_t>(uniqindex)];
int count = 0; int count = 0;
@ -568,7 +568,7 @@ void LoadDiabMonsts()
void DeleteMonster(size_t activeIndex) void DeleteMonster(size_t activeIndex)
{ {
const auto &monster = Monsters[ActiveMonsters[activeIndex]]; const Monster &monster = Monsters[ActiveMonsters[activeIndex]];
if ((monster.flags & MFLAG_BERSERK) != 0) { if ((monster.flags & MFLAG_BERSERK) != 0) {
AddUnLight(monster.lightId); AddUnLight(monster.lightId);
} }
@ -1420,7 +1420,7 @@ bool MonsterGotHit(Monster &monster)
void ReleaseMinions(const Monster &leader) void ReleaseMinions(const Monster &leader)
{ {
for (size_t i = 0; i < ActiveMonsterCount; i++) { 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) { if (minion.leaderRelation == LeaderRelation::Leashed && minion.getLeader() == &leader) {
minion.setLeader(nullptr); minion.setLeader(nullptr);
} }
@ -2209,7 +2209,7 @@ void FallenAi(Monster &monster)
if (m <= 0) if (m <= 0)
continue; continue;
auto &otherMonster = Monsters[m - 1]; Monster &otherMonster = Monsters[m - 1];
if (otherMonster.ai != MonsterAIID::Fallen) if (otherMonster.ai != MonsterAIID::Fallen)
continue; continue;
@ -3494,7 +3494,7 @@ void WeakenNaKrul()
if (currlevel != 24 || static_cast<size_t>(UberDiabloMonsterIndex) >= ActiveMonsterCount) if (currlevel != 24 || static_cast<size_t>(UberDiabloMonsterIndex) >= ActiveMonsterCount)
return; return;
auto &monster = Monsters[UberDiabloMonsterIndex]; Monster &monster = Monsters[UberDiabloMonsterIndex];
PlayEffect(monster, MonsterSound::Death); PlayEffect(monster, MonsterSound::Death);
monster.armorClass -= 50; monster.armorClass -= 50;
int hp = monster.maxHitPoints / 2; int hp = monster.maxHitPoints / 2;
@ -3961,7 +3961,7 @@ void GolumAi(Monster &golem)
} }
if ((golem.flags & MFLAG_NO_ENEMY) == 0) { 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 mex = golem.position.tile.x - enemy.position.future.x;
int mey = golem.position.tile.y - enemy.position.future.y; int mey = golem.position.tile.y - enemy.position.future.y;
golem.direction = GetDirection(golem.position.tile, enemy.position.tile); golem.direction = GetDirection(golem.position.tile, enemy.position.tile);
@ -4008,7 +4008,7 @@ void GolumAi(Monster &golem)
void DeleteMonsterList() void DeleteMonsterList()
{ {
for (int i = 0; i < MAX_PLRS; i++) { for (int i = 0; i < MAX_PLRS; i++) {
auto &golem = Monsters[i]; Monster &golem = Monsters[i];
if (!golem.isInvalid) if (!golem.isInvalid)
continue; continue;
@ -4377,7 +4377,7 @@ void PrintMonstHistory(int mt)
void PrintUniqueHistory() void PrintUniqueHistory()
{ {
auto &monster = Monsters[pcursmonst]; Monster &monster = Monsters[pcursmonst];
if (*sgOptions.Gameplay.showMonsterType) { if (*sgOptions.Gameplay.showMonsterType) {
AddPanelString(fmt::format(fmt::runtime(_("Type: {:s}")), GetMonsterTypeText(monster.data()))); 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) void MissToMonst(Missile &missile, Point position)
{ {
assert(static_cast<size_t>(missile._misource) < MaxMonsters); assert(static_cast<size_t>(missile._misource) < MaxMonsters);
auto &monster = Monsters[missile._misource]; Monster &monster = Monsters[missile._misource];
Point oldPosition = missile.position.tile; Point oldPosition = missile.position.tile;
monster.occupyTile(position, false); monster.occupyTile(position, false);
@ -4500,7 +4500,7 @@ Monster *FindUniqueMonster(UniqueMonsterType monsterType)
{ {
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
int monsterId = ActiveMonsters[i]; int monsterId = ActiveMonsters[i];
auto &monster = Monsters[monsterId]; Monster &monster = Monsters[monsterId];
if (monster.uniqueType == monsterType) if (monster.uniqueType == monsterType)
return &monster; return &monster;
} }

6
Source/msg.cpp

@ -758,7 +758,7 @@ void DeltaLeaveSync(uint8_t bLevel)
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
const unsigned ma = ActiveMonsters[i]; const unsigned ma = ActiveMonsters[i];
auto &monster = Monsters[ma]; Monster &monster = Monsters[ma];
if (monster.hitPoints == 0) if (monster.hitPoints == 0)
continue; continue;
DMonsterStr &delta = deltaLevel.monster[ma]; DMonsterStr &delta = deltaLevel.monster[ma];
@ -1818,7 +1818,7 @@ size_t OnMonstDamage(const TCmd *pCmd, Player &player)
if (gbBufferMsgs != 1) { if (gbBufferMsgs != 1) {
if (&player != MyPlayer) { if (&player != MyPlayer) {
if (player.isOnActiveLevel() && monsterIdx < MaxMonsters) { if (player.isOnActiveLevel() && monsterIdx < MaxMonsters) {
auto &monster = Monsters[monsterIdx]; Monster &monster = Monsters[monsterIdx];
monster.tag(player); monster.tag(player);
if (monster.hitPoints > 0) { if (monster.hitPoints > 0) {
monster.hitPoints -= SDL_SwapLE32(message.dwDam); monster.hitPoints -= SDL_SwapLE32(message.dwDam);
@ -2700,7 +2700,7 @@ void DeltaLoadLevel()
if (deltaLevel.monster[i].position.x == 0xFF) if (deltaLevel.monster[i].position.x == 0xFF)
continue; continue;
auto &monster = Monsters[i]; Monster &monster = Monsters[i];
M_ClearSquares(monster); M_ClearSquares(monster);
{ {
const WorldTilePosition position = deltaLevel.monster[i].position; const WorldTilePosition position = deltaLevel.monster[i].position;

2
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); CreateTypeItem(bookcase.position, false, ItemType::Misc, IMISC_BOOK, sendLootMsg, false);
if (Quests[Q_ZHAR].IsAvailable()) { 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 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.uniqueType == UniqueMonsterType::Zhar
&& zhar.activeForTicks == UINT8_MAX && zhar.activeForTicks == UINT8_MAX

14
Source/player.cpp

@ -329,7 +329,7 @@ void DeadItem(Player &player, Item &&itm, Displacement direction)
int DropGold(Player &player, int amount, bool skipFullStacks) int DropGold(Player &player, int amount, bool skipFullStacks)
{ {
for (int i = 0; i < player._pNumInv && amount > 0; i++) { 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)) if (item._itype != ItemType::Gold || (skipFullStacks && item._ivalue == MaxGold))
continue; continue;
@ -1779,7 +1779,7 @@ void Player::RestorePartialMana()
void Player::ReadySpellFromEquipment(inv_body_loc bodyLocation, bool forceSpell) 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 (item._itype == ItemType::Staff && IsValidSpell(item._iSpell) && item._iCharges > 0 && item._iStatFlag) {
if (forceSpell || _pRSpell == SpellID::Invalid || _pRSplType == SpellType::Invalid) { if (forceSpell || _pRSpell == SpellID::Invalid || _pRSplType == SpellType::Invalid) {
_pRSpell = item._iSpell; _pRSpell = item._iSpell;
@ -1877,19 +1877,19 @@ void Player::UpdatePreviewCelSprite(_cmd_id cmdId, Point point, uint16_t wParam1
switch (cmdId) { switch (cmdId) {
case _cmd_id::CMD_RATTACKID: { case _cmd_id::CMD_RATTACKID: {
auto &monster = Monsters[wParam1]; Monster &monster = Monsters[wParam1];
dir = GetDirection(position.future, monster.position.future); dir = GetDirection(position.future, monster.position.future);
graphic = player_graphic::Attack; graphic = player_graphic::Attack;
break; break;
} }
case _cmd_id::CMD_SPELLID: { case _cmd_id::CMD_SPELLID: {
auto &monster = Monsters[wParam1]; Monster &monster = Monsters[wParam1];
dir = GetDirection(position.future, monster.position.future); dir = GetDirection(position.future, monster.position.future);
graphic = GetPlayerGraphicForSpell(static_cast<SpellID>(wParam2)); graphic = GetPlayerGraphicForSpell(static_cast<SpellID>(wParam2));
break; break;
} }
case _cmd_id::CMD_ATTACKID: { case _cmd_id::CMD_ATTACKID: {
auto &monster = Monsters[wParam1]; Monster &monster = Monsters[wParam1];
point = monster.position.future; point = monster.position.future;
minimalWalkDistance = 2; minimalWalkDistance = 2;
if (!CanTalkToMonst(monster)) { if (!CanTalkToMonst(monster)) {
@ -2674,7 +2674,7 @@ StartPlayerKill(Player &player, DeathReason deathReason)
if (&player != MyPlayer && dropItems) { if (&player != MyPlayer && dropItems) {
// Ensure that items are removed for remote players // Ensure that items are removed for remote players
// The dropped items will be synced seperatly (by the remote client) // The dropped items will be synced seperatly (by the remote client)
for (auto &item : player.InvBody) { for (Item &item : player.InvBody) {
item.clear(); item.clear();
} }
CalcPlrInv(player, false); CalcPlrInv(player, false);
@ -2728,7 +2728,7 @@ StartPlayerKill(Player &player, DeathReason deathReason)
} }
if (dropItems) { if (dropItems) {
Direction pdd = player._pdir; Direction pdd = player._pdir;
for (auto &item : player.InvBody) { for (Item &item : player.InvBody) {
pdd = Left(pdd); pdd = Left(pdd);
DeadItem(player, item.pop(), Displacement(pdd)); DeadItem(player, item.pop(), Displacement(pdd));
} }

4
Source/sync.cpp

@ -26,7 +26,7 @@ void SyncOneMonster()
{ {
for (size_t i = 0; i < ActiveMonsterCount; i++) { for (size_t i = 0; i < ActiveMonsterCount; i++) {
const unsigned m = ActiveMonsters[i]; const unsigned m = ActiveMonsters[i];
auto &monster = Monsters[m]; Monster &monster = Monsters[m];
sgnMonsterPriority[m] = MyPlayer->position.tile.ManhattanDistance(monster.position.tile); sgnMonsterPriority[m] = MyPlayer->position.tile.ManhattanDistance(monster.position.tile);
if (monster.activeForTicks == 0) { if (monster.activeForTicks == 0) {
sgnMonsterPriority[m] += 0x1000; sgnMonsterPriority[m] += 0x1000;
@ -38,7 +38,7 @@ void SyncOneMonster()
void SyncMonsterPos(TSyncMonster &monsterSync, int ndx) void SyncMonsterPos(TSyncMonster &monsterSync, int ndx)
{ {
auto &monster = Monsters[ndx]; Monster &monster = Monsters[ndx];
monsterSync._mndx = ndx; monsterSync._mndx = ndx;
monsterSync._mx = monster.position.tile.x; monsterSync._mx = monster.position.tile.x;
monsterSync._my = monster.position.tile.y; monsterSync._my = monster.position.tile.y;

Loading…
Cancel
Save