diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/inventory.cc | 9 | ||||
-rw-r--r-- | src/core/inventory.h | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/core/inventory.cc b/src/core/inventory.cc index 03cd21e..4b9a2e5 100644 --- a/src/core/inventory.cc +++ b/src/core/inventory.cc @@ -97,5 +97,14 @@ void Inventory::recalculate() } } +const long Inventory::max_amount(const long credits, const long price, const float volume) const +{ + if ((price * volume) == 0) { + return 0; + } + + return math::min((long)(capacity_available() / volume), credits / price); +} + } // namespace core diff --git a/src/core/inventory.h b/src/core/inventory.h index 805d943..7aaf299 100644 --- a/src/core/inventory.h +++ b/src/core/inventory.h @@ -66,13 +66,21 @@ public: } /** - * @brief return the availableinventory capacity, in cubic meters + * @brief return the available inventory capacity, in cubic meters */ inline const float capacity_available() const { return inventory_capacity - inventory_capacity_used; } /** + * @brief returns the number of units of an item that can be stored in this inventory + * @param credits number of player credits, limits the amount + * @param price price of a single unit + * @param volume volume of a single unit + */ + const long max_amount(const long credits, const long price, const float volume) const; + + /** * @brief search the inventory for a specific item type */ Item *find(const Info *info) const; |