]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/inventory.h
Minimap messages: Improve 'disabled by server' message
[dragonfireclient.git] / src / inventory.h
index 04c8156c8f8d9518b270ba93f457b2429687e8cb..465aa66db346934fb95314765c5b1b2199fc4e68 100644 (file)
@@ -17,10 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef INVENTORY_HEADER
-#define INVENTORY_HEADER
+#pragma once
 
-#include "debug.h"
 #include "itemdef.h"
 #include "irrlichttypes.h"
 #include "itemstackmetadata.h"
@@ -28,16 +26,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <ostream>
 #include <string>
 #include <vector>
+#include <cassert>
 
 struct ToolCapabilities;
 
 struct ItemStack
 {
-       ItemStack() {}
+       ItemStack() = default;
+
        ItemStack(const std::string &name_, u16 count_,
                        u16 wear, IItemDefManager *itemdef);
 
-       ~ItemStack() {}
+       ~ItemStack() = default;
 
        // Serialization
        void serialize(std::ostream &os) const;
@@ -111,12 +111,15 @@ struct ItemStack
        const ToolCapabilities& getToolCapabilities(
                        IItemDefManager *itemdef) const
        {
-               ToolCapabilities *cap;
-               cap = itemdef->get(name).tool_capabilities;
-               if(cap == NULL)
-                       cap = itemdef->get("").tool_capabilities;
-               assert(cap != NULL);
-               return *cap;
+               const ToolCapabilities *item_cap =
+                       itemdef->get(name).tool_capabilities;
+
+               if (item_cap == NULL)
+                       // Fall back to the hand's tool capabilities
+                       item_cap = itemdef->get("").tool_capabilities;
+
+               assert(item_cap != NULL);
+               return metadata.getToolCapabilities(*item_cap); // Check for override
        }
 
        // Wear out (only tools)
@@ -133,23 +136,20 @@ struct ItemStack
                                wear += amount;
                        return true;
                }
-               else
-               {
-                       return false;
-               }
+
+               return false;
        }
 
        // If possible, adds newitem to this item.
        // If cannot be added at all, returns the item back.
        // If can be added partly, decremented item is returned back.
        // If can be added fully, empty item is returned.
-       ItemStack addItem(const ItemStack &newitem,
-                       IItemDefManager *itemdef);
+       ItemStack addItem(ItemStack newitem, IItemDefManager *itemdef);
 
        // Checks whether newitem could be added.
        // If restitem is non-NULL, it receives the part of newitem that
        // would be left over after adding.
-       bool itemFits(const ItemStack &newitem,
+       bool itemFits(ItemStack newitem,
                        ItemStack *restitem,  // may be NULL
                        IItemDefManager *itemdef) const;
 
@@ -174,7 +174,7 @@ class InventoryList
 {
 public:
        InventoryList(const std::string &name, u32 size, IItemDefManager *itemdef);
-       ~InventoryList();
+       ~InventoryList() = default;
        void clearItems();
        void setSize(u32 newsize);
        void setWidth(u32 newWidth);
@@ -311,5 +311,3 @@ class Inventory
        IItemDefManager *m_itemdef;
        bool m_dirty = false;
 };
-
-#endif