From 3ff57559e36d3254c64e334fbe3bdd47398fe16f Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Thu, 2 Dec 2021 00:31:10 +0100 Subject: ItemHandler initialisation is a constant expression (#5344) * Transition to non-pointer item handler * That is my destructor - I decide when I leave this world * I declare your destruction private and you final --- src/UI/SlotArea.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/UI/SlotArea.cpp') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 6d27ea834..28f3054ce 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -138,8 +138,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA else if ((Slot.m_ItemType <= 0) || DraggingItem.IsEqual(Slot)) { // Drop one item in slot - cItemHandler * Handler = ItemHandler(Slot.m_ItemType); - if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Handler->GetMaxStackSize())) + if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Slot.GetMaxStackSize())) { char OldSlotCount = Slot.m_ItemCount; @@ -177,8 +176,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA else { // Same type, add items: - cItemHandler * Handler = ItemHandler(DraggingItem.m_ItemType); - int FreeSlots = Handler->GetMaxStackSize() - Slot.m_ItemCount; + int FreeSlots = DraggingItem.GetMaxStackSize() - Slot.m_ItemCount; if (FreeSlots < 0) { ASSERT(!"Bad item stack size - where did we get more items in a slot than allowed?"); @@ -365,7 +363,7 @@ void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ // Different items continue; } - char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already @@ -636,8 +634,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) } else if (DraggingItem.IsEqual(Result)) { - cItemHandler * Handler = ItemHandler(Result.m_ItemType); - if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Handler->GetMaxStackSize()) + if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Result.GetMaxStackSize()) { DraggingItem.m_ItemCount += Result.m_ItemCount; Recipe.ConsumeIngredients(Grid); @@ -928,7 +925,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C } if (!DraggingItem.IsEmpty()) { - if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize()))) + if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= Slot.GetMaxStackSize()))) { return; } @@ -1004,7 +1001,7 @@ void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo // Different items continue; } - char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already @@ -1151,7 +1148,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) RepairCost += Sacrifice.m_RepairCost; // Can we repair with sacrifce material? - if (Target.IsDamageable() && cItemHandler::GetItemHandler(Target)->CanRepairWithRawMaterial(Sacrifice.m_ItemType)) + if (Target.IsDamageable() && Target.GetHandler().CanRepairWithRawMaterial(Sacrifice.m_ItemType)) { // Tool and armor repair with special item (iron / gold / diamond / ...) int DamageDiff = std::min(static_cast(Target.m_ItemDamage), static_cast(Target.GetMaxDamage()) / 4); @@ -1620,7 +1617,7 @@ void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Playe { // It's lapis, put it in the lapis spot. const cItem * Slot = GetSlot(1, a_Player); - char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already @@ -2036,7 +2033,7 @@ void cSlotAreaFurnace::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, return; } - char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already @@ -2300,7 +2297,7 @@ void cSlotAreaBrewingstand::DistributeStack(cItem & a_ItemStack, cPlayer & a_Pla return; } - char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount; if (NumFit <= 0) { // Full stack already -- cgit v1.2.3