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-11-12 20:53:35 +0000
committerStijn Buys <ingar@osirion.org>2009-11-12 20:53:35 +0000
commit5ddb64795cc959916eeedbec8dc3f65c06f49698 (patch)
treeee7231607b0bf49528570e5d3badcdedcb33f54e /src
parent3605a7bd8fffebfba38d31025b6f33cb82626a3b (diff)
initial commodities and entity inventory, bump network proto version to 18
Diffstat (limited to 'src')
-rw-r--r--src/auxiliary/functions.cc2
-rw-r--r--src/core/Makefile.am4
-rw-r--r--src/core/commandbuffer.cc8
-rw-r--r--src/core/entity.cc23
-rw-r--r--src/core/entity.h17
-rw-r--r--src/core/gameconnection.cc2
-rw-r--r--src/core/gameinterface.cc5
-rw-r--r--src/core/info.cc111
-rw-r--r--src/core/info.h98
-rw-r--r--src/core/inventory.cc69
-rw-r--r--src/core/inventory.h64
-rw-r--r--src/core/item.cc100
-rw-r--r--src/core/item.h116
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netconnection.cc22
-rw-r--r--src/core/netserver.cc2
-rw-r--r--src/game/base/Makefile.am4
-rw-r--r--src/game/base/commodity.cc25
-rw-r--r--src/game/base/commodity.h23
-rw-r--r--src/game/base/game.cc87
-rw-r--r--src/game/base/game.h6
-rw-r--r--src/game/base/shipmodel.cc75
-rw-r--r--src/game/base/shipmodel.h18
-rw-r--r--src/render/render.cc12
24 files changed, 599 insertions, 296 deletions
diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc
index 5dbc012..668c108 100644
--- a/src/auxiliary/functions.cc
+++ b/src/auxiliary/functions.cc
@@ -159,6 +159,8 @@ void to_label(std::string &text)
pos++;
} else if ((text[pos] >= '0') && (text[pos] <= '9')) {
pos++;
+ } else if (text[pos] == '/') {
+ pos++;
} else {
text.erase(pos, 1);
}
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index c780239..fce79a6 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc \
descriptions.cc entity.cc extension.cc func.cc gameconnection.cc gameinterface.cc \
- gameserver.cc info.cc item.cc loader.cc module.cc netclient.cc netconnection.cc \
+ gameserver.cc info.cc item.cc inventory.cc loader.cc module.cc netclient.cc netconnection.cc \
netplayer.cc netserver.cc parser.cc player.cc stats.cc timer.cc zone.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \
@@ -14,4 +14,4 @@ noinst_LTLIBRARIES = libcore.la
noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \
gameconnection.h gameinterface.h gameserver.h message.h module.h net.h netclient.h \
netconnection.h netserver.h player.h range.h stats.h timer.h parser.h descriptions.h \
- extension.h loader.h info.h item.h
+ extension.h loader.h info.h item.h inventory.h
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index eb13382..fc98e21 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -87,11 +87,6 @@ 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);
@@ -197,9 +192,6 @@ 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/entity.cc b/src/core/entity.cc
index ce313e6..d01d825 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -114,6 +114,9 @@ Entity::Entity(const unsigned int flags) :
entity_visible = true;
entity_serverside = false;
+
+ entity_inventory = 0;
+ entity_info = 0;
memset(entity_extension, 0, sizeof(entity_extension));
@@ -133,6 +136,9 @@ Entity::Entity(std::istream & is)
entity_created = true;
entity_destroyed = false;
+
+ entity_inventory = 0;
+ entity_info = 0;
memset(entity_extension, 0, sizeof(entity_extension));
}
@@ -151,6 +157,10 @@ Entity::~Entity()
delete(*it);
}
menus().clear();
+
+ // delete inventory
+ if (entity_inventory)
+ delete entity_inventory;
if (entity_zone)
entity_zone->remove(this);
@@ -168,6 +178,19 @@ void Entity::clear_updates()
entity_oldzone = 0;
}
+void Entity::set_info(Info *info)
+{
+ entity_info = info;
+}
+
+void Entity::set_inventory(Inventory *inventory)
+{
+ if (entity_inventory && (entity_inventory != inventory)) {
+ delete entity_inventory;
+ }
+ entity_inventory = inventory;
+}
+
void Entity::set_zone(Zone *zone)
{
if (entity_zone == zone)
diff --git a/src/core/entity.h b/src/core/entity.h
index 92cb5ab..ed0b1f8 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -26,6 +26,7 @@ class EntityControlable;
#include "core/extension.h"
#include "core/descriptions.h"
+#include "core/inventory.h"
#include "core/player.h"
#include "core/zone.h"
@@ -169,6 +170,11 @@ public:
return entity_visible;
}
+ ///entity inventory
+ inline Inventory *inventory() {
+ return entity_inventory;
+ }
+
/// entity menus
inline Menus &menus() {
return entity_menus;
@@ -303,6 +309,14 @@ public:
return entity_color_second;
}
+ /**
+ * @brief add an inventory to this entity
+ * Entity takes ownership over the inventory pointer
+ */
+ void set_inventory(Inventory *inventory);
+
+ void set_info(Info *info);
+
/* ---- deserializers -------------------------------------- */
/// receive a client-to-server update from a stream
@@ -390,6 +404,9 @@ private:
Zone* entity_oldzone;
Menus entity_menus;
+
+ Inventory* entity_inventory;
+ Info* entity_info;
Extension* entity_extension[4];
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index b615b5f..c0a769c 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -99,8 +99,6 @@ Info *GameConnection::info(const std::string &label)
// create a new information record and set the label
info = new Info(label);
- Info::add(info);
-
info->text().push_back("Requesting information...");
// send an information request to the server
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 272c349..b37f11a 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -13,7 +13,6 @@
#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"
@@ -142,13 +141,9 @@ void GameInterface::clear()
// remove all models
model::Model::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/info.cc b/src/core/info.cc
index 745bc3b..4e5399a 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -12,14 +12,65 @@
namespace core
{
-Info::Registry Info::info_registry;
+/* ---- class Info ------------------------------------------------- */
+
+// default constructor
+Info::Info()
+{
+ static_info_id_counter++;
+ info_id = static_info_id_counter;
+
+ info_model = 0;
+ info_timestamp = 0;
+
+ add(this);
+}
Info::Info(const std::string & label)
{
+ static_info_id_counter++;
+ info_id = static_info_id_counter;
+
+ info_timestamp = 0;
+ info_model = 0;
+
info_label.assign(label);
aux::to_lowercase(info_label);
aux::strip_quotes(info_label);
+
+ add(this);
+}
+
+Info::Info(const unsigned int id)
+{
+ info_id = id;
+
+ info_timestamp = 0;
+ info_model = 0;
+
+ add(this);
+}
+
+Info::~Info()
+{
+ info_text.clear();
+ info_label.clear();
+ info_modelname.clear();
+ info_text.clear();
info_timestamp = 0;
+ info_model = 0;
+}
+
+void Info::set_label(const std::string & label)
+{
+ info_label.assign(label);
+ aux::to_label(info_label);
+}
+
+void Info::set_label(const char *label)
+{
+ info_label.assign(label);
+ aux::to_label(info_label);
}
void Info::set_name(const std::string & name)
@@ -42,6 +93,11 @@ void Info::set_modelname(const char *modelname)
info_modelname.assign(modelname);
}
+void Info::set_model(const model::Model *model)
+{
+ info_model = model;
+}
+
void Info::set_timestamp(const unsigned long timestamp)
{
info_timestamp = timestamp;
@@ -71,7 +127,7 @@ void Info::clear_text()
void Info::serialize_server_update(std::ostream & os) const
{
- os << '"' << name() << "\" \"" << modelname() << "\" " << info_text.size() << " ";
+ os << '"' << label() << "\" \"" << name() << "\" \"" << modelname() << "\" " << info_text.size() << " ";
for (Text::const_iterator it = info_text.begin(); it != info_text.end(); it++) {
if (it != info_text.begin())
@@ -86,6 +142,12 @@ void Info::receive_server_update(std::istream &is)
std::string n;
char c;
+ // read label
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
+ info_label.assign(n);
+
// read name
while ((is.get(c)) && (c != '"'));
while ((is.get(c)) && (c != '"'))
@@ -114,13 +176,6 @@ void Info::receive_server_update(std::istream &is)
}
}
-Info::~Info()
-{
- info_text.clear();
- info_modelname.clear();
- info_text.clear();
-}
-
void Info::print() const
{
con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl;
@@ -130,20 +185,24 @@ void Info::print() const
}
}
+
/* ---- static info registry --------------------------------------- */
+Info::Registry Info::info_registry;
+unsigned int Info::static_info_id_counter = 0;
+
void Info::add(Info *info)
{
- if (find(info->label()))
- return;
-
- info_registry[info->label()] = info;
+ info_registry.push_back(info);
}
Info *Info::find(const char *label)
{
+ if (!label)
+ return 0;
+
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
- Info *info = (*it).second;
+ Info *info = (*it);
if (info->label().compare(label) == 0) {
return info;
}
@@ -153,8 +212,11 @@ Info *Info::find(const char *label)
Info *Info::find(const std::string & label)
{
+ if (!label.size())
+ return 0;
+
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
- Info *info = (*it).second;
+ Info *info = (*it);
if (info->label().compare(label) == 0) {
return info;
}
@@ -162,19 +224,34 @@ Info *Info::find(const std::string & label)
return 0;
}
+Info *Info::find(const unsigned int id)
+{
+ if (!id)
+ return 0;
+
+ for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
+ Info *info = (*it);
+ if (info->id() == id) {
+ return info;
+ }
+ }
+ return 0;
+}
+
void Info::clear()
{
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
- Info *info = (*it).second;;
+ Info *info = (*it);
delete info;
}
info_registry.clear();
+ static_info_id_counter = 0;
}
void Info::list()
{
for (Registry::iterator it = info_registry.begin(); it != info_registry.end(); it++) {
- Info *info = (*it).second;;
+ Info *info = (*it);
con_print << info->label() << std::endl;
}
con_print << info_registry.size() << " registered info " << aux::plural("record", info_registry.size()) << std::endl;
diff --git a/src/core/info.h b/src/core/info.h
index 8395954..9f1fab8 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -9,7 +9,7 @@
#include <iostream>
#include <string>
-#include <map>
+#include <vector>
#include <deque>
#include "model/model.h"
@@ -18,19 +18,34 @@ namespace core
{
/**
- * an information record
+ * @brief an information record
+ * An information record holds extended information about a specific entity or item class.
+ * This information isexchanged between server and the client, and can be used to build
+ * HUD widgets/
*/
class Info
{
public:
+ /// type definition for the text description
+ typedef std::deque<std::string> Text;
+
+ /// create a new labeled information record
+ Info();
+
/// create a new labeled information record
Info(const std::string & label);
+
+ Info(const unsigned int id);
/// delete the information record
~Info();
- typedef std::deque<std::string> Text;
+ /* ---- inspectors ------------------------------------------------- */
+ inline const unsigned int id() const {
+ return info_id;
+ }
+
inline const std::string & label() const {
return info_label;
}
@@ -42,15 +57,26 @@ public:
inline const std::string & modelname() const {
return info_modelname;
}
+
+ inline const model::Model *model() const {
+ return info_model;
+ }
inline const unsigned long &timestamp() const {
return info_timestamp;
}
+ /// text description
inline Text & text() {
return info_text;
}
+ /* ---- mutators --------------------------------------------------- */
+
+ void set_label(const std::string & name);
+
+ void set_label(const char *name);
+
void set_name(const std::string & name);
void set_name(const char *name);
@@ -58,16 +84,12 @@ public:
void set_modelname(const std::string & modelname);
void set_modelname(const char *modelname);
+
+ void set_model(const model::Model *model);
/// set the timestamp
void set_timestamp(const unsigned long timestamp);
- /// clear the timestamp
- void clear_timestamp();
-
- /// add a line of info text
- void add_text(const char *text);
-
/// add a line of info text
void add_text(const std::string & text);
@@ -76,25 +98,54 @@ public:
/// print info to sys::con_out
void print() const;
+
+ /// clear the timestamp
+ void clear_timestamp();
+ /// add a line of info text
+ void add_text(const char *text);
+
+ /* ---- serializers ------------------------------------------------ */
+
/// serialize a server-to-client update on a stream
void serialize_server_update(std::ostream & os) const;
/// receive a server-to-client update from a stream
void receive_server_update(std::istream &is);
- /* ---- static info registry --------------------------------------- */
+private:
- typedef std::map<std::string, Info*> Registry;
+ unsigned int info_id;
+
+ std::string info_label;
+ std::string info_name;
+ std::string info_modelname;
+
+ const model::Model* info_model;
+
+ long info_credits;
+ unsigned long info_timestamp;
- /// add an item to the info regsitry
- static void add(Info *info);
+ Text info_text;
- /// search the info registry for a labeled item
+ /* ---- static info registry --------------------------------------- */
+
+public:
+ /// info registry type definition
+ typedef std::vector<Info*> Registry;
+
+ /// the info registry
+ static inline Registry & registry() {
+ return info_registry;
+ }
+ /// search the info registry for a labeled item
static Info *find(const char * label);
- /// search the info registry for a labeled item
+ /// search the info registry for a label
static Info *find(const std::string & label);
+
+ /// search the info registry for an id
+ static Info *find(const unsigned int id);
/// clear the info registry
static void clear();
@@ -102,21 +153,12 @@ public:
/// list the info registry
static void list();
- /// the info registry
- static inline Registry & registry() {
- return info_registry;
- }
-
private:
- std::string info_label;
- std::string info_name;
- std::string info_modelname;
- Text info_text;
-
- long info_credits;
- static Registry info_registry;
+ /// add a record to the info registry
+ static void add(Info *info);
- unsigned long info_timestamp;
+ static Registry info_registry;
+ static unsigned int static_info_id_counter;
};
}
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
+
diff --git a/src/core/inventory.h b/src/core/inventory.h
new file mode 100644
index 0000000..0a1db92
--- /dev/null
+++ b/src/core/inventory.h
@@ -0,0 +1,64 @@
+/*
+ core/inventory.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CORE_INVENTORY_H__
+#define __INCLUDED_CORE_INVENTORY_H__
+
+#include "core/item.h"
+
+#include <vector>
+
+namespace core
+{
+
+/**
+ * @brief an entity inventory
+ */
+class Inventory
+{
+public:
+ /**
+ * @brief type definition for the items in the inventory
+ */
+ typedef std::vector<Item *> Items;
+
+ /**
+ * @brief default constructor
+ */
+ Inventory();
+
+ /**
+ * @brief default destructor
+ */
+ ~Inventory();
+
+ /**
+ * @brief add an item to the inventory
+ */
+ void add(Item *item);
+
+ /**
+ * @brief remove an item from the inventory and delete it
+ */
+ void remove(Item *item);
+
+ /**
+ * @brief removes all items from the inventory and delete them
+ */
+ void clear();
+
+ /**
+ * @brief search the inventory for a specific item type
+ */
+ Item *find(unsigned int const class_id, unsigned int const info_id);
+
+private:
+ Items inventory_items;
+};
+
+} // namsepace core
+
+#endif // __INCLUDED_CORE_INVENTORY_H__
diff --git a/src/core/item.cc b/src/core/item.cc
index 53da74d..a029674 100644
--- a/src/core/item.cc
+++ b/src/core/item.cc
@@ -12,102 +12,24 @@ 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)
+Item::Item(const unsigned int class_id, const unsigned int info_id)
{
- if (label) {
- itemclass_label.assign(label);
- } else {
- itemclass_label.clear();
- }
-}
-
-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) {
- itemtype_label.assign(label);
- } else {
- itemtype_label.clear();
- }
-
- itemtype_baseprice = 0;
+ item_class_id = class_id;
+ item_info_id = info_id;
+
+ item_amount = 0;
+ item_info = Info::find(info_id);
}
-void ItemType::set_name(const std::string &name)
+Item::~Item()
{
- itemtype_name.assign(name);
+ item_amount = 0;
}
-void ItemType::set_baseprice(const float baseprice)
+void Item::set_amount(const int amount)
{
- itemtype_baseprice = 0;
+ item_amount = amount;
}
-} // class core
+} // namespace core
diff --git a/src/core/item.h b/src/core/item.h
index 0845c21..f88da57 100644
--- a/src/core/item.h
+++ b/src/core/item.h
@@ -7,93 +7,53 @@
#ifndef __INCLUDED_CORE_ITEM_H__
#define __INCLUDED_CORE_ITEM_H__
-#include <string>
-#include <vector>
+#include "core/info.h"
namespace core
{
/**
- * @brief a specific type of item in the game
- * Examples are tritanium hull armor, ion cannon, iron ore
+ * @brief an item in the inventory of an entity
+ * The info record represents the type of the item
*/
-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;
- }
-
- inline const float baseprice() {
- return itemtype_baseprice;
- }
-
- void set_name(const std::string &name);
-
- void set_baseprice(const float baseprice);
-
+ Item(const unsigned int class_id, const unsigned int info_id);
+
+ ~Item();
+
+ /* ---- inspectors --------------------------------------------- */
+
+ inline unsigned int class_id() const { return item_class_id; }
+
+ inline unsigned int info_id() const { return item_info_id; }
+
+ /**
+ * @brief associated amount
+ */
+ inline int amount() const { return item_amount; }
+
+ /**
+ * @brief information record
+ */
+ inline Info *info();
+
+ /* ---- mutators ----------------------------------------------- */
+
+ /**
+ * @brief set associated amount
+ */
+ void set_amount(const int amount);
+
private:
- std::string itemtype_label;
- std::string itemtype_name;
-
- float itemtype_baseprice;
+ unsigned int item_class_id;
+ unsigned int item_info_id;
+ int item_amount;
+
+ Info *item_info;
};
+} // namespace core
-/**
- * @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;
-};
-
-class Item
-{
-public:
- typedef std::vector<ItemClass *> Registry;
-
- 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();
-
- static Registry item_registry;
-};
-
-}
-#endif
+#endif // __INCLUDED_CORE_ITEM_H__
diff --git a/src/core/net.h b/src/core/net.h
index cd8e249..a217d94 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 17;
+const unsigned int PROTOCOLVERSION = 18;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index c37fe05..39a25a3 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -436,6 +436,8 @@ void NetConnection::send_info_request(Info *info)
* frame
* sup <id>
* pif <id>
+ * pid <id>
+ * inf <id>
* zone
*/
void NetConnection::parse_incoming_message(const std::string & message)
@@ -684,29 +686,27 @@ void NetConnection::parse_incoming_message(const std::string & message)
return;
}
}
+
} else if (command == "inf") {
// incoming info record
- std::string label;
- char c;
-
- while ((msgstream.get(c)) && (c != '"'));
- while ((msgstream.get(c)) && (c != '"'))
- label += c;
-
- if (label.size()) {
- Info *info = Info::find(label);
+ unsigned int id;
+ if (msgstream >> id) {
+
+ Info *info = Info::find(id);
if (!info) {
- info = new Info(label);
- Info::add(info);
+ info = new Info(id);
}
info->receive_server_update(msgstream);
info->clear_timestamp();
+
} else {
con_warn << "Received empty information record!" << std::endl;
}
+
} else if (command == "sup") {
+
if (connection_state == Connected) {
unsigned int id;
if (msgstream >> id) {
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 1ae928b..c4eef11 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -562,7 +562,7 @@ void NetServer::send_player_disconnect_info(NetClient *client, Player *player)
void NetServer::send_info_update(NetClient *client, Info *info)
{
std::ostringstream msg;
- msg << "inf " << '"' << info->label() << '"' << ' ';
+ msg << "inf " << info->id() << ' ';
info->serialize_server_update(msg);
msg << '\n';
client->send_raw(msg.str());
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index d2dfe64..c3625a0 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -2,8 +2,8 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game
METASOURCES = AUTO
libbase_la_LDFLAGS = -avoid-version
noinst_LTLIBRARIES = libbase.la
-libbase_la_SOURCES = collision.cc game.cc jumppoint.cc navpoint.cc physics.cc \
+libbase_la_SOURCES = collision.cc commodity.cc game.cc jumppoint.cc navpoint.cc physics.cc \
planet.cc racetrack.cc ship.cc shipdealer.cc shipmodel.cc star.cc station.cc
-noinst_HEADERS = game.h collision.h jumppoint.h navpoint.h physics.h planet.h \
+noinst_HEADERS = game.h collision.h commodity.h jumppoint.h navpoint.h physics.h planet.h \
racetrack.h ship.h shipdealer.h shipmodel.h star.h station.h
diff --git a/src/game/base/commodity.cc b/src/game/base/commodity.cc
new file mode 100644
index 0000000..a9eb8c8
--- /dev/null
+++ b/src/game/base/commodity.cc
@@ -0,0 +1,25 @@
+/*
+ base/commodity.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "base/commodity.h"
+#include "auxiliary/functions.h"
+#include "sys/sys.h"
+
+namespace game
+{
+
+/* ---- class Commodity -------------------------------------------- */
+
+Commodity::Commodity() : core::Info()
+{
+}
+
+Commodity::~Commodity()
+{
+}
+
+} // namespace game
+
diff --git a/src/game/base/commodity.h b/src/game/base/commodity.h
new file mode 100644
index 0000000..e226505
--- /dev/null
+++ b/src/game/base/commodity.h
@@ -0,0 +1,23 @@
+/*
+ base/commodity.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_BASE_COMMODITY_H__
+#define __INCLUDED_BASE_COMMODITY_H__
+
+#include "core/info.h"
+
+namespace game
+{
+class Commodity : public core::Info {
+
+public:
+ Commodity();
+ ~Commodity();
+};
+
+} // namespace game
+
+#endif // __INCLUDED_BASE_COMMODITY_H__
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 7ec54b3..fa02857 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -16,6 +16,7 @@
#include "filesystem/inifile.h"
#include "base/game.h"
#include "base/collision.h"
+#include "base/commodity.h"
#include "base/navpoint.h"
#include "base/jumppoint.h"
#include "base/planet.h"
@@ -336,6 +337,11 @@ Game::Game() : core::Module("Project::OSiRiON", true)
Physics::init();
+ if (!load_commodities()) {
+ abort();
+ return;
+ }
+
if (!load_ships()) {
abort();
return;
@@ -814,6 +820,68 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
return true;
}
+// read commodities
+bool Game::load_commodities()
+{
+ filesystem::IniFile commoditiesini;
+ commoditiesini.open("commodities");
+ if (!commoditiesini.is_open()) {
+ con_error << "Could not open " << commoditiesini.name() << "!" << std::endl;
+ return false;
+ }
+
+ con_print << "^BLoading commodities..." << std::endl;
+
+ size_t count = 0;
+
+ Commodity *commodity = 0;
+ std::string str;
+
+ while (commoditiesini.getline()) {
+ if (commoditiesini.got_key()) {
+
+ if (commoditiesini.section().compare("commodity") == 0) {
+ if (commoditiesini.got_key_string("label", str)) {
+ commodity->set_label(std::string("cargo/" + str));
+ count++;
+ continue;
+
+ } else if (commoditiesini.got_key_string("name", str)) {
+ con_debug << " " << str << std::endl;
+ commodity->set_name(str);
+ continue;
+
+ } else if (commoditiesini.got_key_string("info", str)) {
+ commodity->add_text(str);
+ continue;
+
+ } else if (commoditiesini.got_key_string("model", str)) {
+ commodity->set_modelname(str);
+ continue;
+
+ } else {
+ commoditiesini.unkown_key();
+ }
+ }
+
+ } else if (commoditiesini.got_section()) {
+
+ if (commoditiesini.got_section("commodity")) {
+ commodity = new Commodity();
+
+ } else if (commoditiesini.got_section()) {
+ commoditiesini.unknown_section();
+ }
+ }
+ }
+
+ // add commodity infos
+ con_debug << " " << commoditiesini.name() << " " << count << " commodities" << std::endl;
+
+ commoditiesini.close();
+ return true;
+}
+
// read ship model specifications
bool Game::load_ships()
{
@@ -827,6 +895,9 @@ bool Game::load_ships()
return false;
}
+ con_print << "^BLoading ships..." << std::endl;
+
+ unsigned int type_id = 0;
ShipModel *shipmodel = 0;
std::string label;
std::string infostr;
@@ -872,7 +943,8 @@ bool Game::load_ships()
}
} else if (shipsini.got_section("ship")) {
if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel;
- shipmodel = new ShipModel();
+ type_id++;
+ shipmodel = new ShipModel(type_id);
if (!Default::shipmodel)
Default::shipmodel = shipmodel;
@@ -880,20 +952,15 @@ bool Game::load_ships()
shipsini.unknown_section();
}
}
- shipsini.close();
if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel;
// add shipmodel infos
- for (ShipModel::iterator it = ShipModel::registry.begin(); it != ShipModel::registry.end(); it++) {
- ShipModel *shipmodel = (*it).second;
- core::Info *info = new core::Info("ship/" + shipmodel->label());
- shipmodel->generate_info(info);
- core::Info::add(info);
- }
-
+ ShipModel::generate_info();
con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl;
+ shipsini.close();
+
return true;
}
@@ -987,5 +1054,3 @@ void Game::player_disconnect(core::Player *player)
}
} // namespace game
-
-
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 65084d3..a7e476e 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -34,6 +34,10 @@ const unsigned int jumppoint_enttype = 260;
const unsigned int jumpgate_enttype = 261;
const unsigned int station_enttype = 262;
+// info class type constants
+const unsigned int shipmodel_class_id = 1;
+const unsigned int commodity_class_id = 2;
+
/// default player settings
class Default
{
@@ -85,6 +89,8 @@ private:
bool load_menus(core::Entity *entity, const std::string &menufilename);
+ bool load_commodities();
+
bool load_ships();
bool load_player();
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 6233120..fe1c88c 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -14,9 +14,9 @@ namespace game
{
// the ship model registry
-std::map<std::string, ShipModel *> ShipModel::registry;
+ShipModel::Registry ShipModel::registry;
-ShipModel::ShipModel()
+ShipModel::ShipModel(const unsigned int type_id)
{
//default specifications
shipmodel_acceleration = 1.0f; // thruster acceleration in game untits/second^2
@@ -26,6 +26,7 @@ ShipModel::ShipModel()
shipmodel_maxcargo = 0;
shipmodel_jumpdrive = false;
+ shipmodel_type_id = type_id;
}
ShipModel::~ShipModel()
@@ -51,45 +52,51 @@ void ShipModel::print()
con_print << " cargo: ^B" << maxcargo() << std::endl;
}
-void ShipModel::generate_info(core::Info *info)
+void ShipModel::generate_info()
{
- info->clear_text();
-
- info->set_name(name());
- info->set_modelname(modelname());
-
- // info text form ships.ini
- for (core::Info::Text::iterator it = shipmodel_infotext.begin(); it != shipmodel_infotext.end(); it++) {
- info->add_text((*it));
- }
-
- info->add_text("");
- info->add_text("^BSpecifications:^N");
- std::stringstream str;
- str << "price: ^B" << price() << " ^Ncredits";
- info->add_text(str.str());
- str.str("");
+ for (iterator it = registry.begin(); it != registry.end(); it++) {
+ ShipModel *shipmodel = (*it).second;
+ core::Info *info = new core::Info("ship/" + shipmodel->label());
+
+ info->clear_text();
+ info->set_name(shipmodel->name());
+ info->set_modelname(shipmodel->modelname());
+
+ // info text form ships.ini
+ for (core::Info::Text::iterator tit = shipmodel->shipmodel_infotext.begin();
+ tit != shipmodel->shipmodel_infotext.end(); tit++) {
+
+ info->add_text((*tit));
+ }
- str << "cargo hold: ^B" << 0.1f * maxcargo() << " ^Nmetric tonnes";
- info->add_text(str.str());
- str.str("");
+ info->add_text("");
+ info->add_text("^BSpecifications:^N");
+ std::stringstream str;
+ str << "price: ^B" << shipmodel->price() << " ^Ncredits";
+ info->add_text(str.str());
+ str.str("");
- str << "top speed: ^B" << 100.0f * maxspeed() << " ^Nmps";
- info->add_text(str.str());
- str.str("");
+ str << "cargo hold: ^B" << 0.1f * shipmodel->maxcargo() << " ^Nmetric tonnes";
+ info->add_text(str.str());
+ str.str("");
- str << "response: ^B" << turnspeed() << " ^Ndps";
- info->add_text(str.str());
- str.str("");
+ str << "top speed: ^B" << 100.0f * shipmodel->maxspeed() << " ^Nmps";
+ info->add_text(str.str());
+ str.str("");
- str << "acceleration: ^B" << acceleration() << " ^Nstandard";
- info->add_text(str.str());
- str.str("");
+ str << "response: ^B" << shipmodel->turnspeed() << " ^Ndps";
+ info->add_text(str.str());
+ str.str("");
- if (shipmodel_jumpdrive) {
- str << "hyperspace jump drive capable";
+ str << "acceleration: ^B" << shipmodel->acceleration() << " ^Nstandard";
info->add_text(str.str());
str.str("");
+
+ if (shipmodel->shipmodel_jumpdrive) {
+ str << "hyperspace jump drive capable";
+ info->add_text(str.str());
+ str.str("");
+ }
}
}
@@ -154,7 +161,7 @@ ShipModel *ShipModel::search(const std::string searchname)
return 0;
}
-// add a new ship model
+// add a ship model
void ShipModel::add(ShipModel *shipmodel)
{
ShipModel *m = find(shipmodel->label());
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 0cfe87e..d3048b2 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -19,7 +19,7 @@ namespace game
class ShipModel
{
public:
- ShipModel();
+ ShipModel(const unsigned int type_id);
~ShipModel();
void print();
@@ -53,6 +53,11 @@ public:
inline const std::string & modelname() const {
return shipmodel_modelname;
}
+
+ /// type id
+ inline unsigned int type_id() {
+ return shipmodel_type_id;
+ }
/// price of the ship
inline const long price() const {
@@ -89,9 +94,6 @@ public:
shipmodel_maxcargo = maxcargo;
}
- /// generate an info object for this shipmodel
- void generate_info(core::Info *info);
-
/// indicates of this model can be equiped with a jump drive
bool shipmodel_jumpdrive;
@@ -104,6 +106,8 @@ public:
/* ---- static registry ------------------------------------ */
+ typedef std::map<std::string, ShipModel *> Registry;
+
typedef std::map<std::string, ShipModel *>::iterator iterator;
/// find an exact match
@@ -116,7 +120,7 @@ public:
static ShipModel *search(const std::string label);
/// the ship model registry
- static std::map<std::string, ShipModel *> registry;
+ static std::map<std::string, ShipModel *> registry;
/// clear the ship model registry
static void clear();
@@ -126,6 +130,9 @@ public:
/// add a new ship model
static void add(ShipModel *shipmodel);
+
+ /// generate info records
+ static void generate_info();
private:
@@ -136,6 +143,7 @@ private:
long shipmodel_price;
+ unsigned int shipmodel_type_id;
};
}
diff --git a/src/render/render.cc b/src/render/render.cc
index 03c5c87..66b7d42 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -189,6 +189,12 @@ void clear()
delete ext_render(entity);
}
}
+
+ // clear info models
+ for (core::Info::Registry::iterator it = core::Info::registry().begin(); it != core::Info::registry().end(); it++) {
+ core::Info *info = (*it);
+ info->set_model(0);
+ }
// clear model registry
model::Model::clear();
@@ -214,9 +220,11 @@ void load()
// load info models
for (core::Info::Registry::iterator it = core::Info::registry().begin(); it != core::Info::registry().end(); it++) {
- core::Info *info = (*it).second;
+ core::Info *info = (*it);
if (info->modelname().size()) {
- model::Model::load(info->modelname());
+ info->set_model(model::Model::load(info->modelname()));
+ } else {
+ info->set_model(0);
}
}
}