From a95028547981614e06ea7a6d22b853b85418cea3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 15 Apr 2009 17:08:51 +0000 Subject: added info registry, list_info added network info transfer added info based buy menu and related game changes --- src/game/base/game.cc | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'src/game/base/game.cc') 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; -- cgit v1.2.3