diff --git a/assets/items/Tools.items b/assets/items/Tools.items
index 3e6a0f3..c9c061d 100644
--- a/assets/items/Tools.items
+++ b/assets/items/Tools.items
@@ -11,7 +11,8 @@
+ attackDuration="0.2"
+ energyCost="1" />
@@ -25,7 +26,8 @@
+ attackDuration="0.2"
+ energyCost="1" />
diff --git a/assets/items/Weapons.items b/assets/items/Weapons.items
index c994fbf..7982c2a 100644
--- a/assets/items/Weapons.items
+++ b/assets/items/Weapons.items
@@ -11,7 +11,8 @@
+ attackDuration="0.4"
+ energyCost="1.5" />
@@ -24,7 +25,8 @@
+ attackDuration="0.4"
+ energyCost="0.9" />
\ No newline at end of file
diff --git a/assets/scenes/Game.scene b/assets/scenes/Game.scene
index 29c1821..f10be84 100644
--- a/assets/scenes/Game.scene
+++ b/assets/scenes/Game.scene
@@ -26,12 +26,10 @@
-
-
-
-
-
-
+
+
diff --git a/src/components/basic/Inventory.cpp b/src/components/basic/Inventory.cpp
new file mode 100644
index 0000000..6bb68c9
--- /dev/null
+++ b/src/components/basic/Inventory.cpp
@@ -0,0 +1,148 @@
+/*
+ * Inventory.cpp
+ *
+ * Created on: Dec 11, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+#include
+
+namespace farmlands {
+namespace components {
+namespace basic {
+
+Inventory::Inventory()
+ : m_capacity(10),
+ m_items(nullptr)
+{
+}
+
+Inventory::~Inventory()
+{
+ delete[] m_items;
+}
+
+model::Component* Inventory::clone()
+{
+ Inventory* clone = new Inventory();
+ clone->m_capacity = m_capacity;
+ return clone;
+}
+
+void Inventory::dump(unsigned level)
+{
+ for (unsigned i = 0; i < level; i++)
+ std::cout<<" ";
+
+ std::cout << " .Component: Inventory capacity=" << m_capacity << "\n";
+}
+
+void Inventory::onCreate()
+{
+ // Allocate items array
+ m_items = new model::GameObject*[m_capacity];
+ memset(m_items, 0, sizeof(m_items[0]) * m_capacity);
+
+ // Find all children
+ for (auto it = gameObject->childrenBegin(); it != gameObject->childrenEnd(); it++)
+ {
+ InventoryItem* item = (*it)->component();
+ if (item)
+ {
+ Assert(item->slot >= 0 && item->slot < m_capacity, "Inventory item slot out of range.");
+ Assert(m_items[item->slot] == nullptr, "Multiple items on one slot.");
+
+ m_items[item->slot] = *it;
+ }
+ }
+}
+
+bool Inventory::add(model::GameObject* item)
+{
+ Assert(m_items != nullptr, "Inventory not initialized");
+ Assert(item != nullptr, "Cannot add null object.");
+
+ // Find an empty slot
+ size_t slot = (size_t)-1;
+ for (size_t i = 0; i < m_capacity; i++)
+ if (m_items[i] == nullptr)
+ {
+ slot = i;
+ break;
+ }
+
+ if (slot != (size_t)-1)
+ {
+ set(slot, item);
+ return true;
+ }
+ return false;
+}
+
+void Inventory::remove(size_t slot)
+{
+ Assert(m_items != nullptr, "Inventory not initialized.");
+ Assert(slot < m_capacity, "Slot out of range.");
+
+ if (m_items[slot] != nullptr)
+ {
+ m_items[slot]->removeComponent();
+ m_items[slot] = nullptr;
+ }
+}
+
+void Inventory::set(size_t slot, model::GameObject* item)
+{
+ Assert(m_items != nullptr, "Inventory not initialized.");
+ Assert(slot < m_capacity, "Slot out of range.");
+ Assert(item != nullptr, "Cannot set null element.");
+
+ remove(slot);
+ m_items[slot] = item;
+
+ // Update InventoryItem
+ if (!item->haveComponent())
+ item->addComponent(new InventoryItem);
+
+ InventoryItem* invItem = item->component();
+ invItem->slot = slot;
+}
+
+model::GameObject* Inventory::get(size_t slot)
+{
+ Assert(m_items != nullptr, "Inventory not initialized.");
+ Assert(slot < m_capacity, "Slot out of range.");
+
+ return m_items[slot];
+}
+
+void Inventory::setCapacity(size_t capacity)
+{
+ if (m_items != nullptr)
+ {
+ // Remove extra items
+ for (size_t i = m_capacity; i < capacity; i++)
+ remove(i);
+
+ // Reallocate
+ model::GameObject** old = m_items;
+ m_items = new model::GameObject*[capacity];
+ memset(m_items, 0, sizeof(m_items[0]) * capacity);
+
+ // Copy old objects
+ for (size_t i = 0; i < std::min(m_capacity, capacity); i++)
+ m_items[i] = old[i];
+
+ // Finish
+ delete[] old;
+ }
+
+ m_capacity = capacity;
+}
+
+} /* namespace basic */
+} /* namespace components */
+} /* namespace farmlands */
+
diff --git a/src/components/basic/Inventory.h b/src/components/basic/Inventory.h
new file mode 100644
index 0000000..b363388
--- /dev/null
+++ b/src/components/basic/Inventory.h
@@ -0,0 +1,77 @@
+/*
+ * Inventory.h
+ *
+ * Created on: Dec 11, 2016
+ * Author: tibi
+ */
+
+#ifndef COMPONENTS_INVENTORY_INVENTORY_H_
+#define COMPONENTS_INVENTORY_INVENTORY_H_
+
+#include
+#include
+
+namespace farmlands {
+namespace components {
+namespace basic {
+
+ class Inventory: public model::Component
+ {
+ public:
+ Inventory();
+ virtual ~Inventory();
+
+ virtual model::Component* clone() override;
+ virtual void dump(unsigned level) override;
+
+ virtual void onCreate() override;
+
+ // Inventory management
+ /**
+ * Adds a game object to first available slot.
+ * Game object should be already added as a child of the parent game object.
+ * If object doesn't have an "InventoryItem" component, it will be added.
+ * @returns true if added successfully, false if no empty slot was found.
+ */
+ bool add(model::GameObject* item);
+
+ /**
+ * Removes the game object from the given slot.
+ * Doesn't delete/destroy the game object from the parent game object.
+ * Destroys the "InventoryItem" component of the object.
+ */
+ void remove(size_t slot);
+
+ /**
+ * Sets the given game object (which should be a child of the parent game object) to have the given slot.
+ * If there is an item in that slot, it is removed.
+ */
+ void set(size_t slot, model::GameObject* item);
+
+ /**
+ * Gets the game object in the given slot.
+ * Returns null if slot is empty.
+ */
+ model::GameObject* get(size_t slot);
+
+ /**
+ * Modifies the capacity of the inventory.
+ * If the inventory is already initialized, objects might be removed.
+ */
+ void setCapacity(size_t capacity);
+
+ /**
+ * Gets the capacity
+ */
+ size_t capacity() const { return m_capacity; }
+
+ private:
+ size_t m_capacity;
+ model::GameObject** m_items;
+ };
+
+} /* namespace basic */
+} /* namespace components */
+} /* namespace farmlands */
+
+#endif /* COMPONENTS_INVENTORY_INVENTORY_H_ */
diff --git a/src/components/basic/InventoryItem.cpp b/src/components/basic/InventoryItem.cpp
new file mode 100644
index 0000000..2159ecf
--- /dev/null
+++ b/src/components/basic/InventoryItem.cpp
@@ -0,0 +1,36 @@
+/*
+ * InventoryItem.cpp
+ *
+ * Created on: Dec 11, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+
+namespace farmlands {
+namespace components {
+namespace basic {
+
+InventoryItem::~InventoryItem()
+{
+}
+
+model::Component* InventoryItem::clone()
+{
+ InventoryItem* item = new InventoryItem();
+ item->slot = slot;
+ return item;
+}
+
+void InventoryItem::dump(unsigned level)
+{
+ for (unsigned i = 0; i < level; i++)
+ std::cout<<" ";
+
+ std::cout << " .Component: InventoryItem slot=" << slot << "\n";
+}
+
+} /* namespace basic */
+} /* namespace components */
+} /* namespace farmlands */
diff --git a/src/components/basic/InventoryItem.h b/src/components/basic/InventoryItem.h
new file mode 100644
index 0000000..05bac11
--- /dev/null
+++ b/src/components/basic/InventoryItem.h
@@ -0,0 +1,32 @@
+/*
+ * InventoryItem.h
+ *
+ * Created on: Dec 11, 2016
+ * Author: tibi
+ */
+
+#ifndef COMPONENTS_INVENTORY_INVENTORYITEM_H_
+#define COMPONENTS_INVENTORY_INVENTORYITEM_H_
+
+#include
+
+namespace farmlands {
+namespace components {
+namespace basic {
+
+ class InventoryItem: public model::Component
+ {
+ public:
+ virtual ~InventoryItem();
+
+ virtual model::Component* clone() override;
+ virtual void dump(unsigned level) override;
+
+ size_t slot;
+ };
+
+} /* namespace basic */
+} /* namespace components */
+} /* namespace farmlands */
+
+#endif /* COMPONENTS_INVENTORY_INVENTORYITEM_H_ */
diff --git a/src/components/items/Axe.cpp b/src/components/items/Axe.cpp
index c333375..1806985 100644
--- a/src/components/items/Axe.cpp
+++ b/src/components/items/Axe.cpp
@@ -34,7 +34,7 @@ void Axe::dump(unsigned level)
std::cout << " .Component: Axe\n";
}
-void Axe::performAction(float x, float y, model::Direction d)
+void Axe::performAction(float lookX, float lookY, float* timeCost, float* hpCost, float* energyCost)
{
}
diff --git a/src/components/items/Axe.h b/src/components/items/Axe.h
index 7f6f4cc..267b036 100644
--- a/src/components/items/Axe.h
+++ b/src/components/items/Axe.h
@@ -8,14 +8,14 @@
#ifndef COMPONENTS_ITEMS_AXE_H_
#define COMPONENTS_ITEMS_AXE_H_
-#include
+#include
#include
namespace farmlands {
namespace components {
namespace items {
- class Axe: public model::Component, public IPlayerAction
+ class Axe: public model::Component, public model::IPlayerAction
{
public:
Axe();
@@ -24,7 +24,7 @@ namespace items {
virtual model::Component* clone() override;
virtual void dump(unsigned level) override;
- virtual void performAction(float x, float y, model::Direction d) override;
+ virtual void performAction(float lookX, float lookY, float* timeCost, float* hpCost, float* energyCost) override;
};
} /* namespace items */
diff --git a/src/components/items/Giftable.cpp b/src/components/items/Giftable.cpp
index e876356..e14b6f9 100644
--- a/src/components/items/Giftable.cpp
+++ b/src/components/items/Giftable.cpp
@@ -26,7 +26,7 @@ model::Component* Giftable::clone()
return new Giftable();
}
-void Giftable::performAction(float x, float y, model::Direction d)
+void Giftable::performAction(float lookX, float lookY, float* timeCost, float* hpCost, float* energyCost)
{
}
diff --git a/src/components/items/Giftable.h b/src/components/items/Giftable.h
index efec8c2..507d03e 100644
--- a/src/components/items/Giftable.h
+++ b/src/components/items/Giftable.h
@@ -8,14 +8,14 @@
#ifndef CONTROLLER_ITEMS_GIFTABLE_H_
#define CONTROLLER_ITEMS_GIFTABLE_H_
-#include
+#include
#include
namespace farmlands {
namespace components {
namespace items {
- class Giftable: public model::Component, public IPlayerAction
+ class Giftable: public model::Component, public model::IPlayerAction
{
public:
Giftable();
@@ -24,7 +24,7 @@ namespace items {
virtual model::Component* clone() override;
virtual void dump(unsigned level) override;
- virtual void performAction(float x, float y, model::Direction d) override;
+ virtual void performAction(float lookX, float lookY, float* timeCost, float* hpCost, float* energyCost) override;
};
} /* namespace items */
diff --git a/src/components/items/Hoe.cpp b/src/components/items/Hoe.cpp
index 1b86c34..2bbe8cc 100644
--- a/src/components/items/Hoe.cpp
+++ b/src/components/items/Hoe.cpp
@@ -53,16 +53,13 @@ void Hoe::onInitialize()
m_map = (*it)->component