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/game | |
parent | 3605a7bd8fffebfba38d31025b6f33cb82626a3b (diff) |
initial commodities and entity inventory, bump network proto version to 18
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/Makefile.am | 4 | ||||
-rw-r--r-- | src/game/base/commodity.cc | 25 | ||||
-rw-r--r-- | src/game/base/commodity.h | 23 | ||||
-rw-r--r-- | src/game/base/game.cc | 87 | ||||
-rw-r--r-- | src/game/base/game.h | 6 | ||||
-rw-r--r-- | src/game/base/shipmodel.cc | 75 | ||||
-rw-r--r-- | src/game/base/shipmodel.h | 18 |
7 files changed, 186 insertions, 52 deletions
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; }; } |