Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-06-28 14:03:45 +0000
committerStijn Buys <ingar@osirion.org>2009-06-28 14:03:45 +0000
commit16ba873bd12d8748fdc8a5169f4b76867ec50a3c (patch)
treeb28a91a12c8a3d35b3aaf5afda83888f6d8fb92a /src
parentf0ea15eb49c55e1c0f6a9fe43eb668cb00141e24 (diff)
item library foundation
Diffstat (limited to 'src')
-rw-r--r--src/core/commandbuffer.cc9
-rw-r--r--src/core/gameinterface.cc4
-rw-r--r--src/core/item.cc81
-rw-r--r--src/core/item.h66
4 files changed, 143 insertions, 17 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index e288b0f..fbb9cfd 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -17,6 +17,7 @@
#include "core/gameconnection.h"
#include "core/func.h"
#include "core/info.h"
+#include "core/item.h"
#include "core/cvar.h"
#include "core/loader.h"
#include "core/zone.h"
@@ -86,6 +87,11 @@ void func_list_module(std::string const &args)
Loader::list();
}
+void func_list_item(std::string const &args)
+{
+ Item::list();
+}
+
void func_set(std::string const &args)
{
std::istringstream argstream(args);
@@ -191,6 +197,9 @@ void CommandBuffer::init()
func = Func::add("list_info", (FuncPtr)func_list_info);
func->set_info("list info records");
+ func = Func::add("list_item", (FuncPtr)func_list_item);
+ func->set_info("list item types");
+
func = Func::add("list_var", (FuncPtr)func_list_var);
func->set_info("list variables");
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 0ade34b..53e5715 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -13,6 +13,7 @@
#include "core/cvar.h"
#include "core/func.h"
#include "core/info.h"
+#include "core/item.h"
#include "core/gameinterface.h"
#include "core/player.h"
#include "core/zone.h"
@@ -124,6 +125,9 @@ void GameInterface::clear()
// remove infos
Info::clear();
+ // remove items
+ Item::clear();
+
// clear player list
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
Player *player = (*it);
diff --git a/src/core/item.cc b/src/core/item.cc
index 116685b..7b4633c 100644
--- a/src/core/item.cc
+++ b/src/core/item.cc
@@ -5,10 +5,50 @@
*/
#include "core/item.h"
+#include "sys/sys.h"
namespace core
{
+/* ---- class Item ------------------------------------------------- */
+
+
+Item::Registry Item::item_registry;
+
+void Item::add_class(ItemClass * itemclass)
+{
+
+}
+
+void Item::add_type(ItemClass * itemclass, ItemType *itemtype)
+{
+
+}
+
+void Item::find_class(const char *label)
+{
+
+}
+
+void Item::clear()
+{
+ for (Registry::iterator it = item_registry.begin(); it != item_registry.end(); it++) {
+ delete (*it);
+ }
+ item_registry.clear();
+}
+
+void Item::list()
+{
+ for (Registry::iterator it = item_registry.begin(); it != item_registry.end(); it++) {
+ con_print << " item class ^B " << (*it)->name() << std::endl;
+ (*it)->list();
+ }
+ con_print << item_registry.size() << " registered item classes" << std::endl;
+}
+
+/* ---- class ItemClass -------------------------------------------- */
+
ItemClass::ItemClass(const char *label)
{
if (label) {
@@ -18,6 +58,36 @@ ItemClass::ItemClass(const char *label)
}
}
+ItemClass::~ItemClass()
+{
+ for (Types::iterator it = itemclass_types.begin(); it != itemclass_types.end(); it++) {
+ delete (*it);
+ }
+}
+
+void ItemClass::list()
+{
+}
+
+void ItemClass::set_name(const std::string &name)
+{
+ itemclass_name.assign(name);
+}
+
+void ItemClass::add_type(ItemType *itemtype)
+{
+ for (Types::iterator it = itemclass_types.begin(); it != itemclass_types.end(); it++) {
+ con_print << " " << (*it)->name() << std::endl;
+ }
+}
+
+ItemType *ItemClass::find_type(const char *label)
+{
+ return 0;
+}
+
+/* ---- class ItemType --------------------------------------------- */
+
ItemType::ItemType(const char *label)
{
if (label) {
@@ -29,4 +99,15 @@ ItemType::ItemType(const char *label)
itemtype_baseprice = 0;
}
+void ItemType::set_name(const std::string &name)
+{
+ itemtype_name.assign(name);
+}
+
+void ItemType::set_baseprice(const float baseprice)
+{
+ itemtype_baseprice = 0;
}
+
+} // class core
+
diff --git a/src/core/item.h b/src/core/item.h
index d390c2d..8299444 100644
--- a/src/core/item.h
+++ b/src/core/item.h
@@ -8,48 +8,80 @@
#define __INCLUDED_CORE_ITEM_H__
#include <string>
+#include <vector>
namespace core {
/**
+ * @brief a specific type of item in the game
+ * Examples are tritanium hull armor, ion cannon, iron ore
+ */
+class ItemType
+{
+public:
+ ItemType(const char *label);
+
+ inline const std::string &label() { return itemtype_label; }
+
+ inline const std::string &name() { return itemtype_name; }
+
+ inline const float baseprice() { return itemtype_baseprice; }
+
+ void set_name(const std::string &name);
+
+ void set_baseprice(const float baseprice);
+
+private:
+ std::string itemtype_label;
+ std::string itemtype_name;
+
+ float itemtype_baseprice;
+};
+
+
+/**
* @brief a class of items
* Examples are armor, cannons, commodities...
*/
class ItemClass
{
public:
+ typedef std::vector<ItemType *> Types;
+
ItemClass(const char *label);
+ ~ItemClass();
inline const std::string &label() { return itemclass_label; }
inline const std::string &name() { return itemclass_name; }
+ ItemType *find_type(const char *label);
+
+ void set_name(const std::string &name);
+
+ void add_type(ItemType *itemtype);
+
+ void list();
+
private:
std::string itemclass_label;
std::string itemclass_name;
+
+ Types itemclass_types;
};
-/**
- * @brief a specific type of item in the game
- * Examples are tritanium hull armor, ion cannon, gems
- */
-class ItemType
+class Item
{
public:
- ItemType(const char *label);
-
- inline const std::string &label() { return itemtype_label; }
-
- inline const std::string &name() { return itemtype_name; }
+ typedef std::vector<ItemClass *> Registry;
- inline const float base_price() { return itemtype_baseprice; }
+ static void add_class(ItemClass * itemclass);
+ static void add_type(ItemClass * itemclass, ItemType *itemtype);
+ static void find_class(const char *label);
+ static void clear();
+ static void list();
-private:
- std::string itemtype_label;
- std::string itemtype_name;
-
- ItemClass *itemtype_class;
- float itemtype_baseprice;
+ static Registry item_registry;
};
}