diff options
author | Stijn Buys <ingar@osirion.org> | 2009-04-15 17:08:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-04-15 17:08:51 +0000 |
commit | a95028547981614e06ea7a6d22b853b85418cea3 (patch) | |
tree | d4d6998a4118a4d8690ce138d586abfba4893179 /src/game | |
parent | 4f33f59571f10019c1e7a0e3640b2f69c159a8cf (diff) |
added info registry, list_info
added network info transfer
added info based buy menu and related game changes
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/collision.cc | 25 | ||||
-rw-r--r-- | src/game/base/game.cc | 44 | ||||
-rw-r--r-- | src/game/base/game.h | 1 | ||||
-rw-r--r-- | src/game/base/shipmodel.cc | 35 | ||||
-rw-r--r-- | src/game/base/shipmodel.h | 8 |
5 files changed, 93 insertions, 20 deletions
diff --git a/src/game/base/collision.cc b/src/game/base/collision.cc index 728ad14..215764c 100644 --- a/src/game/base/collision.cc +++ b/src/game/base/collision.cc @@ -8,26 +8,27 @@ #include "base/game.h" #include "core/zone.h" #include "math/functions.h" -#include "math/vector3f.h" +#include "math/vector3f.h" -namespace game { +namespace game +{ void Collision::distance_test(core::EntityControlable *first, core::Entity *second) { if (!first->owner()) return; - + if (first->state() == core::Entity::Docked) return; - + // FIXME - use distancesquared const float d = math::distance(first->location(), second->location()); const float r = first->radius() + second->radius(); - + if (second->type() == core::Entity::Globe) { // collision with a star or a planet - - if ( (d-r) < 0.0f) { + + if ((d-r) < 0.0f) { // crash zone if ((first->moduletype() == ship_enttype) && (first->state() != core::Entity::Destroyed)) { first->owner()->send_warning("^RBOOM!^N"); @@ -36,9 +37,9 @@ void Collision::distance_test(core::EntityControlable *first, core::Entity *seco } } else if (first->owner()->last_warning() + 5.0f < core::application()->time()) { // warning zone: star corona or planet atmosphere - if ((second->moduletype() == star_enttype) && (d-r < 50.0f)) { + if ((second->moduletype() == star_enttype) && (d-r < 50.0f)) { first->owner()->send_warning("^3Warning: entering star corona!^N"); - } else if ((second->moduletype() == planet_enttype) && (d-r < 15.0f)) { + } else if ((second->moduletype() == planet_enttype) && (d-r < 15.0f)) { first->owner()->send_warning("^3Warning: entering planet gravity well!^N"); } } @@ -49,14 +50,14 @@ void Collision::frame_zone(core::Zone *zone) { core::Zone::Content::iterator first; core::Zone::Content::iterator second; - + for (first = zone->content().begin(); first != zone->content().end(); first ++) { second = first; for (second++; second != zone->content().end(); second++) { - if ( (*first)->type() == core::Entity::Controlable) { + if ((*first)->type() == core::Entity::Controlable) { distance_test(static_cast<core::EntityControlable *>((*first)), (*second)); } else if ((*second)->type() == core::Entity::Controlable) { - distance_test(static_cast<core::EntityControlable *> ((*second)), (*first)); + distance_test(static_cast<core::EntityControlable *>((*second)), (*first)); } } } diff --git a/src/game/base/game.cc b/src/game/base/game.cc index b2824f5..da060b9 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -191,6 +191,26 @@ void Game::func_dock(core::Player *player, core::Entity *entity) } } +// buy request from a player +void Game::func_buy(core::Player *player, const std::string &args) +{ + std::istringstream is(args); + std::string itemtype; + if (!(is >> itemtype)) { + player->send("usage: buy [string] [string] buy type of item, name of item"); + return; + } + + aux::to_label(itemtype); + if ((args.size() > 5 ) && (itemtype.compare("ship") == 0)) { + ShipDealer::func_buy(player, args.substr(5, args.size() - 5)); + } else { + player->send("unkown item type '" + itemtype + "'"); + } + + return; +} + // launch request void Game::func_launch(core::Player *player, std::string const &args) { @@ -308,8 +328,8 @@ Game::Game() : core::Module("Project::OSiRiON", true) func = core::Func::add("spectate", Game::func_spectate); func->set_info("leave the game and spectate"); - func = core::Func::add("buy", ShipDealer::func_buy); - func->set_info("buy a ship"); + func = core::Func::add("buy", Game::func_buy); + func->set_info("[string] [string] buy type of item, name of item"); func = core::Func::add("jump", Game::func_jump); func->set_info("[string] activate or deactivate hyperspace jump drive"); @@ -697,7 +717,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) if (model) { button = new ButtonDescription(); button->set_text("buy " + model->name()); - button->set_command("buy " + model->label()); + button->set_command("buy ship " + model->label(), ButtonDescription::CommandMenu); button->set_modelname(model->modelname()); button->set_alignment(ButtonDescription::Left); menu_dealer->add_button(button); @@ -719,14 +739,14 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) button = new ButtonDescription(); button->set_text("Launch"); - button->set_command("launch"); + button->set_command("launch", ButtonDescription::CommandGame); button->set_alignment(ButtonDescription::Center); menu_main->add_button(button); if (menu_dealer) { button = new ButtonDescription(); button->set_text("Return"); - button->set_command("menu view main"); + button->set_command("main", ButtonDescription::CommandMenu); button->set_alignment(ButtonDescription::Center); menu_dealer->add_button(button); @@ -734,7 +754,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) button = new ButtonDescription(); button->set_text("Ship dealer"); - button->set_command("menu view dealer"); + button->set_command("dealer", ButtonDescription::CommandMenu); button->set_alignment(ButtonDescription::Center); menu_main->add_button(button); } @@ -763,6 +783,7 @@ bool Game::load_ships() ShipModel *shipmodel = 0; std::string label; + std::string infostr; long l; float f; @@ -776,6 +797,9 @@ bool Game::load_ships() continue; } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { continue; + } else if (shipsini.got_key_string("info", infostr)) { + shipmodel->shipmodel_infotext.push_back(infostr); + continue; } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { continue; } else if (shipsini.got_key_long("price", l)) { @@ -814,6 +838,14 @@ bool Game::load_ships() 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); + } + con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; return true; diff --git a/src/game/base/game.h b/src/game/base/game.h index 36de8dc..1f16a9f 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -103,6 +103,7 @@ private: static void func_launch(core::Player *player, std::string const &args); static void func_respawn(core::Player *player, std::string const &args); static void func_goto(core::Player *player, const std::string &args); + static void func_buy(core::Player *player, std::string const &args); }; /// factory function diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc index 78dc125..fc4781a 100644 --- a/src/game/base/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -43,11 +43,42 @@ void ShipModel::clear() void ShipModel::print() { con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << std::endl; + con_print << " price: ^B" << price() << std::endl; con_print << " acceleration: ^B" << acceleration() << std::endl; con_print << " turnspeed: ^B" << turnspeed() << std::endl; con_print << " max speed: ^B" << maxspeed() << std::endl; - con_print << " max cargo: ^B" << maxcargo() << std::endl; - con_print << " price: ^B" << price() << std::endl; + con_print << " cargo: ^B" << maxcargo() << std::endl; +} + +void ShipModel::generate_info(core::Info *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(""); + + str << "cargo hold: ^B" << 0.1f * maxcargo() << " ^Nmetric tonnes"; + info->add_text(str.str()); str.str(""); + + str << "top speed: ^B" << 100.0f * maxspeed() << " ^Nmps"; + info->add_text(str.str()); str.str(""); + + str << "response: ^B" << turnspeed() << " ^Ndps"; + info->add_text(str.str()); str.str(""); + + str << "acceleration: ^B" << acceleration() << " ^Nstandard"; + info->add_text(str.str()); str.str(""); } void ShipModel::list() diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h index c194dc0..9bdf4f5 100644 --- a/src/game/base/shipmodel.h +++ b/src/game/base/shipmodel.h @@ -10,6 +10,8 @@ #include <map> #include <string> +#include "core/info.h" + namespace game { /// ship model specifications @@ -60,6 +62,9 @@ public: /// set size of the cargo hold inline void set_maxcargo(const float maxcargo) { 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; @@ -67,6 +72,9 @@ public: std::string shipmodel_name; std::string shipmodel_modelname; + /// info text + core::Info::Text shipmodel_infotext; + /* ---- static registry ------------------------------------ */ typedef std::map<std::string, ShipModel *>::iterator iterator; |