diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 13:24:16 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 21:23:10 +0100 |
commit | 306ad2effe4d0897453e61ad787e01dc47c33076 (patch) | |
tree | 75b8b291af55e80d01d9eb85afd7d465233a1a57 /src/shopitem.cpp | |
parent | 66599a9896e0cf69b58c0a73152aba4750d87af2 (diff) | |
download | mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.gz mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.bz2 mana-306ad2effe4d0897453e61ad787e01dc47c33076.tar.xz mana-306ad2effe4d0897453e61ad787e01dc47c33076.zip |
General code cleanups
* Use default member initializers
* Use range-based for loops
* Avoid needless pointer references for ShopItem::mDuplicates
* Removed type aliases that are only used once or twice
* Removed more unused includes
* Removed some unused functions
* Removed superfluous .c_str()
* Rely on default copy and assignment operators for Vector class
* Use std::unique_ptr in some places
* Removed duplicated mPlayerMoney updating in SellDialog
* Removed duplicated Game::handleInput call
* Removed unused SDLInput::mMouseInWindow
* Removed remnant of manual widget positioning in HelpWindow
* Removed superfluous initialization of static pointers
Diffstat (limited to 'src/shopitem.cpp')
-rw-r--r-- | src/shopitem.cpp | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 6eb52d18..e966dbbf 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -31,56 +31,28 @@ ShopItem::ShopItem(int inventoryIndex, int id, mPrice(price) { mDisplayName = getInfo().getName() + - " (" + Units::formatCurrency(mPrice).c_str() + ")"; + " (" + Units::formatCurrency(mPrice) + ")"; setInvIndex(inventoryIndex); addDuplicate(inventoryIndex, quantity); } -ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price) -{ - mDisplayName = getInfo().getName() + - " (" + Units::formatCurrency(mPrice).c_str() + ")"; - setInvIndex(-1); - addDuplicate(-1, 0); -} - -ShopItem::~ShopItem() -{ - /** Clear all remaining duplicates on Object destruction. */ - while (!mDuplicates.empty()) - { - delete mDuplicates.top(); - mDuplicates.pop(); - } -} +ShopItem::~ShopItem() = default; void ShopItem::addDuplicate(int inventoryIndex, int quantity) { - auto* di = new DuplicateItem; - di->inventoryIndex = inventoryIndex; - di->quantity = quantity; - mDuplicates.push(di); + DuplicateItem &di = mDuplicates.emplace(); + di.inventoryIndex = inventoryIndex; + di.quantity = quantity; mQuantity += quantity; } -void ShopItem::addDuplicate() -{ - auto* di = new DuplicateItem; - di->inventoryIndex = -1; - di->quantity = 0; - mDuplicates.push(di); -} - int ShopItem::sellCurrentDuplicate(int quantity) { - DuplicateItem* dupl = mDuplicates.top(); - int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity; - dupl->quantity -= sellCount; + DuplicateItem &dupl = mDuplicates.top(); + int sellCount = quantity <= dupl.quantity ? quantity : dupl.quantity; + dupl.quantity -= sellCount; mQuantity -= sellCount; - if (dupl->quantity == 0) - { - delete dupl; + if (dupl.quantity == 0) mDuplicates.pop(); - } return sellCount; } |