diff options
author | Stijn Buys <ingar@osirion.org> | 2009-11-12 20:53:35 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-11-12 20:53:35 +0000 |
commit | 5ddb64795cc959916eeedbec8dc3f65c06f49698 (patch) | |
tree | ee7231607b0bf49528570e5d3badcdedcb33f54e /src/core/inventory.cc | |
parent | 3605a7bd8fffebfba38d31025b6f33cb82626a3b (diff) |
initial commodities and entity inventory, bump network proto version to 18
Diffstat (limited to 'src/core/inventory.cc')
-rw-r--r-- | src/core/inventory.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/core/inventory.cc b/src/core/inventory.cc new file mode 100644 index 0000000..a58664c --- /dev/null +++ b/src/core/inventory.cc @@ -0,0 +1,69 @@ +/* + core/inventory.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/inventory.h" +#include "sys/sys.h" + +namespace core +{ + +/* ---- class Inventory -------------------------------------------- */ + +Inventory::Inventory() +{ + +} + +Inventory::~Inventory() +{ + clear(); +} + +void Inventory::add(Item *item) +{ + for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) { + // check if the item was already added + if ((*it) == item) + return; + } + inventory_items.push_back(item); +} + +void Inventory::remove(Item *item) +{ + for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) { + if ((*it) == item) { + inventory_items.erase(it); + delete item; + return; + } + } +} + +Item *Inventory::find(unsigned int const class_id, unsigned int const info_id) +{ + // sarch the inventory for a specified item type + for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) { + Item *item = (*it); + if ((item->class_id() == class_id) && (item->info_id() == info_id )) { + return item; + } + } + // not found + return 0; +} + +void Inventory::clear() +{ + for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) { + Item *item = (*it); + delete item; + } + inventory_items.clear(); +} + +} // namespace core + |