From 5ddb64795cc959916eeedbec8dc3f65c06f49698 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 12 Nov 2009 20:53:35 +0000 Subject: initial commodities and entity inventory, bump network proto version to 18 --- src/core/inventory.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/core/inventory.cc (limited to 'src/core/inventory.cc') 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 + -- cgit v1.2.3